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堆,然后再从第一堆开始)。你可以获得的石头就是石头个数为偶数的

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

思路:只有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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值