Mancala CodeForces - 975B (水)

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个,要么是奇数个。现在,有一种操作,取走第i堆石头,然后从i+1开始,依次放

入1个石头,直到手中的石头放完(放到第14堆,然后再从第一堆开始)。你可以获得的石头就是石头个数为偶数的

扫描二维码关注公众号,回复: 1501818 查看本文章

堆。问,你最后可以获得多少个石头。

思路:只有14,直接暴力模拟即可。

#include "iostream"
#include "algorithm"
using namespace std;
typedef long long ll;
int a[20],tmp[20];
int main()
{
    ll ans=0,Max;
    for(int i=1;i<=14;i++)
        cin>>a[i];
    for(int i=1;i<=14;i++){
        for(int j=1;j<=14;j++) tmp[j]=a[j];
        Max=0;
        int x=tmp[i],y=i+1;
        tmp[i]=0;
        int n=x/14;
        for(int i=1;i<=14;i++) tmp[i]+=n;
        x%=14;
        while(x){
            y%=14;
            if(y==0) y=14;
            tmp[y++]++;
            x--;
        }
        for(int j=1;j<=14;j++){
            if(tmp[j]&&tmp[j]%2==0)
                Max+=tmp[j];
        }
        ans=max(ans,Max);
    }
    cout<<ans<<endl;
}



猜你喜欢

转载自blog.csdn.net/qq_41874469/article/details/80601251