题目描述:
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.
输入描述:
The only line contains 14 integers a1,a2,…,a14 (0≤ai≤109) — the number of stones in each hole.
It is guaranteed that for any i (1≤i≤14) ai 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
5 1 1 1 1 0 0 0 0 0 0 0 0 0
输出:
4
8
题意:
题意有14堆石头,要么是0个,要么是奇数个。现在,有一种操作,取走第i堆石头,然后从i+1开始,依次放入1个石头,直到手中的石头放完(放到第14堆,然后再从第一堆开始)。你可以获得的石头就是石头个数为偶数的堆。问,你最后可以获得多少个石头。
题解:
n才14,直接暴力搞
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
int a[30],b[30];
ll init(){
for(int i = 1; i <= 14; i ++){
b[i] = a[i];
}
}
int main(){
while(scanf("%lld",&a[1])!=EOF){
ll ans = 0;
for(int i = 2; i <= 14; i ++) scanf("%lld",&a[i]);
for(int i = 1; i <= 14; i ++){
ll sum = 0;
ll t = a[i];
if(t == 0) continue;
init();
b[i] = 0;
ll k = i + 1;
int x = t / 14;
for(int y = 1; y <= 14; y ++) b[y] += x;
t %= 14;
while(t){
if(k > 14) k = 1;
b[k] ++;
t --;
k ++;
}
for(int j = 1; j <= 14; j ++){
if(b[j] % 2 == 0 && b[j]){
sum += b[j];
}
}
ans = max(ans,sum);
}
printf("%I64d\n",ans);
}
return 0;
}