博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #478 (Div. 2) B. Mancala
阅读量:2441 次
发布时间:2019-05-10

本文共 2832 字,大约阅读时间需要 9 分钟。

题目链接:
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 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.

Input

The only line contains 14 integers a1,a2,,a14 (0ai109) — the number of stones in each hole.

It is guaranteed that for any i(1i14) ai 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 7 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 4.

题意:有14个洞,每个洞有一个值啊a[i],从中找一个值大于0的洞,(把这14个洞看成一个环),然后依次给它下一个洞的值+1,并且立刻让自己这个洞的值变为0,(注意只能从中选一个洞进行这个操作,循环到自己本身也是要+1的),最后让你求这些洞值为偶数的和的最大值。
做法基本上是遍历一遍14个洞,然后遍历过程中取一个max,但题目数据ai<=1e9,直接暴力肯定会TLE的,我的一种遍历思路是分两种情况:
1.当a[i]<=14时,直接暴力。
2.a[i]>14时,求一个x=a[i]/14,k=a[i]%14.就可以表示从a[i]开始循环x圈后再走k步,走的那k步总共加了x+1次,其他的只加了x次。这样就可以一次性加完了。
这道题疯狂wa了好多发,哎,还是太菜了啊。
AC代码:
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define rep(i,n) for(int i=1;i<=n;i++)#define m(a,b) memset(a,b,sizeof(a))typedef pair
PII;typedef long long ll;const int MAXN=1e5+10;int main(){ IO; ll a[15],b[15],ans=0,cnt; for(int i=1;i<=14;i++) cin>>a[i]; a[0]=0; for(int i=1;i<=14;i++){ cnt=0; memcpy(b,a,sizeof(ll)*15); if (b[i]>0){ if (b[i]<=14){ b[i]=0; for(int j=i+1,m=1;m<=a[i];j++,m++){ if (j>14) j%=14; b[j]++; } } else{ int x=b[i]/14,k=b[i]%14; b[i]=0; for(int j=i+1,m=1;m<=k;j++,m++){ if (j>14) j%=14; b[j]+=(x+1); } for(int j=i+k+1,m=1;m<=14-k;j++,m++){ if (j>14) j%=14; b[j]+=x; } } } for(int j=1;j<=14;j++) if (b[j]%2==0) cnt+=b[j]; ans=max(ans,cnt); } cout<
<

转载地址:http://hhfqb.baihongyu.com/

你可能感兴趣的文章
Fedora Core 4硬盘安装方法(转)
查看>>
常用的系统状态查询命令(转)
查看>>
『推荐』上G的linux视频教程和电子书FTP下载,速度快内容实用!(转)
查看>>
AIX系统日常管理(转)
查看>>
Fedora Core 6的新特性(转)
查看>>
不得不说 僵尸网络导致垃圾邮件猛增(转)
查看>>
linux网络知识:TCP/IP设置内容(转)
查看>>
GNOME帮助Linux应用于商业桌面环境(转)
查看>>
linux网络知识:与网络设置有关的几个文件(转)
查看>>
Linux文件内容查询命令(转)
查看>>
libc.a 文件恢复(转)
查看>>
SCO UNIX上cpio命令详细用法(转)
查看>>
Linux系统可卸载内核模块完全指南(下)(转)
查看>>
思考-两个大表的关联.txt
查看>>
WIDTH_BUCKET和NTILE函数.txt
查看>>
sql plan baseline(二)
查看>>
第十章 sqlplus的安全性
查看>>
第十三章 sqlplus命令(一)
查看>>
第三章(backup and recovery 笔记)
查看>>
第一章(backup and recovery 笔记)
查看>>