链接:https://vjudge.net/problem/CodeForces-975B
题目
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
Initially, each hole has ai 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 i, he will put one stone in the (i+1)-th hole, then in the (i+2)-th, etc. If he puts a stone in the 14-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.
题意
一共有14个盘子,每个盘子里有a[i]个石头(a[i]要么为0,要么为奇数)。
现在你可以任意选择一个盘子,然后把盘子里的石头分发给后面的盘子,每次发一个。
如果发完第14个盘子之后还有石头,则从第一个继续发,直到石头没了。
你最终的报酬是所有有偶数个石头的盘子里所有的石头。问你最多能拿到多少石头?
思路
既然n只有14,我们就暴力一手。把每个盘子都搞一遍,看哪个报酬最多就用哪个方案。
看代码,伊丽莎白!
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[15],b[15];
int main()
{
while(~scanf("%lld",&a[1]))
{
ll cnt=0;
for(int i=2;i<=14;i++)
scanf("%lld",&a[i]);
for(int i=1;i<=14;i++)
{
ll sum=0;
ll ans=a[i];
if(ans==0) //当前盘子里没有石头
continue;
for(int j=1;j<=14;j++)
b[j]=a[j];
b[i]=0;
int t=ans/14;
for(int j=1;j<=14;j++)
b[j]+=t;
ans%=14;
int pos=i+1;
while(ans)
{
if(pos==15)
pos=1;
b[pos]++;
ans--;
pos++;
} //分发石头的过程,这部分是关键
for(int j=1;j<=14;j++)
{
if(b[j]%2==0)
sum+=b[j];
}
cnt=max(sum,cnt);
}
cout<<cnt<<endl;
}
}
穷,限制了我的想象力。