搬书游戏

#include<iostream>

using namespace std;
int main()
{
    int total,book[101],temp[101];

    cin>>total;

    int i,j;
    for(i=0; i<total; i++)
        cin>>book[i];
    int score=0,c=total;
    while(c>1)
    {
        for(i=0; i<c; i++)
        {
            temp[i]=book[i];

        }
        int index=0,min=10000000;
        int t=book[0];
        for(i=0; i<c; i++)
        {
            if(i<c-1)
                book[i]+=book[i+1];
            else
                book[i]+=t;
        }

        for(i=0; i<c; i++)
        {
            if(min>book[i])
            {
                min=book[i];
                index=i;
            }
        }

        score+=min;
 //       cout<<score<<endl;
        for(i=0,j=0; i<c; i++,j++)
        {
            if(i==index)
            {
                if(index!=c-1)
                {
                    book[i]=min;
                    j++;
                }else
                {
                    book[0]=min;
                }
            }
            else
            {
                book[i]=temp[j];
            }
     //             cout<<book[i]<<" ";
        }
        c--;
    //        cout<<endl;
    }
    cout<<score<<endl;
    return 0;
}

相关文章:

  • 2022-01-12
  • 2021-07-25
  • 2021-09-21
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
猜你喜欢
  • 2021-06-28
  • 2021-12-19
  • 2022-12-23
  • 2021-05-29
  • 2022-02-06
  • 2021-06-16
  • 2021-06-26
相关资源
相似解决方案