B. Mancala

B. Mancala
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.

Initially, each hole has aiai stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.

Note that the counter-clockwise order means if the player takes the stones from hole ii, he will put one stone in the (i+1)(i+1)-th hole, then in the (i+2)(i+2)-th, etc. If he puts a stone in the 1414-th hole, the next one will be put in the first hole.

After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.

Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

Input

The only line contains 14 integers a1,a2,,a14a1,a2,…,a14 (0ai1090≤ai≤109) — the number of stones in each hole.

It is guaranteed that for any ii (1i141≤i≤14aiai is either zero or odd, and there is at least one stone in the board.

Output

Output one integer, the maximum possible score after one move.

Examples
input
Copy
0 1 1 0 0 0 0 0 0 7 0 0 0 0
output
Copy
4
input
Copy
5 1 1 1 1 0 0 0 0 0 0 0 0 0
output
Copy
8
Note

In the first test case the board after the move from the hole with 77 stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to 44.



题意:题不是很好理解,直接简单说吧,输入14个数,每个数必须是奇数或者是0.然后你可以选择一个数把这个数从当前位置的下一个位置,按照顺序依次加1,如果加到最后就从前面开始加,直到当前选择这个数用完。最后把14个数里面是偶数的数加起来,输出最大偶数。例如样例一:前面两个1,分解就不说了,直接后面那个7分解,从7后面那个位置开始加1,知道加到第14个数,还剩余三个,从第一个加到第三个,刚好用完,结果是1 2 2 0 0 0 0 0 0 0 1 1 1 1。偶数加起来为4就是最大答案。前面的最多为2,所以取4.


题解:暴力 注意细节,卡细节很久。因为只有十四个数,我们遍历每个数都来分解,按照题目规则加到其他数上,然后把偶数加起来,输出最大的那个ans。

#include<bits/stdc++.h>
using namespace std;
long long a[20],b[20],ans;
int main()
{
    for(int i=0; i<14; i++)
        cin>>a[i];
    for(int i=0; i<14; i++)
    {
        if(a[i])
        {
            long long cnt=0;
            for(int k=0; k<14; k++)
                b[k]=a[k];
                b[i]=0;
            long long x=a[i]%14,y=a[i]/14;
            long long m=x;
            for(int k=i+1; k<14&&m; k++,m--)
                b[k]++;
            for(int k=0; k<m; k++)
                b[k]++;
            for(int k=0; k<14; k++)
                b[k]+=y;
//                for(int k=0;k<14;k++)
//                    cout<<b[k];
                cout<<endl;
            for(int k=0; k<14; k++)
                if(b[k]%2==0)
                    cnt+=b[k];
            ans=max(ans,cnt);

        }
    }
    cout<<ans;
    return 0;
}


猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/80162140
今日推荐