Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.
![](https://i-blog.csdnimg.cn/blog_migrate/ac2252fd163ad6cafc4498952fb1a46b.png)
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.
The only line contains 14 integers a1,a2,…,a14a1,a2,…,a14 (0≤ai≤1090≤ai≤109) — the number of stones in each hole.
It is guaranteed that for any ii (1≤i≤141≤i≤14) aiai is either zero or odd, and there is at least one stone in the board.
Output one integer, the maximum possible score after one move.
0 1 1 0 0 0 0 0 0 7 0 0 0 0
4
5 1 1 1 1 0 0 0 0 0 0 0 0 0
8
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.
题目:有n个石头洞,每个洞有奇数个或者0个石头,题目说进行一次移动,只能移动一个洞的石子进行下移,题目中有解释;
思路:暴力枚举每个洞,算下每个洞分配多少。。。直接加就好了。。。
代码:
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 15;
ll a[maxn], b[maxn];
void init()
{
for(int i = 1; i <= 14; i++) b[i] = a[i];
}
ll sum()
{
ll ans = 0;
for(int i = 1; i <= 14; i++)
if(b[i]%2 == 0)
ans += b[i];
return ans;
}
int main()
{
for(int i = 1; i <= 14; i++) scanf("%lld", &a[i]);
init();
ll ma = 0;
for(int i = 1; i <= 14; i++)
{
ll k = a[i]; b[i] = 0;
ll c = k/14;
int d = k%14;
for(int j = 1; j <= 14; j++) b[j] += c;
for(int j = i+1; j <= 14&&d>0; j++,d--) b[j]++;
for(int j = 1; j <= d; j++) b[j]++;
ma = max(ma, sum());
init();
}
printf("%lld\n",ma);
return 0;
}