Codeforces Round #478 (Div. 2) B. Mancala

matlab开发-Mancala matlab开发-Mancala。曼卡拉是一个古老的棋类游戏家族,也被称为卡拉。 立即下载
题目链接: 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 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 (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

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 <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
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<int, int> 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<<ans<<endl;
	return 0;
}



STM32硬件SPI驱动ADS1255/1256避坑指南:从Cube MX配置到稳定采样实战 本文详细解析了使用STM32硬件SPI驱动高精度ADC芯片ADS1255/1256的完整流程与关键陷阱。重点阐述了Cube MX中SPI模式(必须为CPOL=1, CPHA=1)、数据帧格式(MSB First)及波特率(建议从256kHz起)的正确配置,并提供了分步读写时序的代码实现与逻辑分析仪调试方法,帮助开发者避开常见坑点,实现稳定可靠的高精度数据采样。 阅读详情

相关推荐

Surface Pro 4/5/6/7保姆级黑苹果安装:从Windows分区到OC引导配置全流程(含EFI文件替换避坑)

本文详细介绍了在Surface Pro 4/5/6/7上安装黑苹果的全流程,包括Windows分区、OC引导配置和EFI文件替换等关键步骤。通过实战经验分享,帮助用户避开常见陷阱,实现Windows与macOS双系统完美共存,特别适合对黑苹果安装感兴趣的Surface Pro用户。

weixin_30300225的博客 1403

CodeForces - 975B:Mancala(暴力)

链接: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 nu

Mr.RainsdRop的胡思乱想 614

Robocopy 参数进阶:/MIR 镜像同步与 /PURGE 删除操作的风险规避指南

本文深入解析Robocopy的/MIR镜像同步与/PURGE删除操作的高级用法及风险规避策略。通过实际案例和四重防护机制,指导用户安全实现目录同步,避免数据丢失风险,特别适用于远程主机间的数据复制与备份场景。

weixin_33462927的博客 372

Codeforces-975B - Mancala - 思维

题解链接: https://lucien.ink/archives/203/ 题目链接: http://codeforces.com/contest/975/problem/B 题目: Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes...

LucienShui 1295

Lisflood

文献:基于SWMM和LISFLOOD-FP模型的居住区低影响开发模拟评价。问题:多个节点溢流同时,不行,待解决。目录下,cmd命令行。

警警的博客 2675

保姆级教程:从零到飞,用QGC地面站搞定PX4无人机全流程配置(含避坑指南)

本文提供了一份详细的QGC地面站使用教程,指导用户从零开始配置PX4无人机,涵盖固件烧录、传感器校准、遥控器设置及航点规划等关键步骤,并包含实用的避坑指南,帮助新手顺利完成首飞。

weixin_30329623的博客 226

Mancala (模拟)

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 pos...

码农的一亩三分地 1084

别再手动备份了!用Python脚本批量导出华为/华三交换机配置(附完整代码)

本文详细介绍了如何使用Python脚本实现华为/华三交换机配置的自动化备份,大幅提升网络运维效率。通过paramiko库建立SSH连接,结合pandas处理设备清单,实现配置的批量导出与规范化存储,解决传统手动备份耗时易错的问题。

weixin_28737603的博客 455

Codeforces Round #478 (Div. 2)

题目链接:http://codeforces.com/contest/975 A. Aramic script time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output In ...

di6499的博客 183

Codex 实战 Skills:编写 Skill 自动为 ESP32 芯片生成 MQTT 订阅与发布的基础代码

为了更清晰地展示 Skill 的工作原理和两种语言的差异,以下提供原理图和比对表格。本文深入探讨了如何利用 Codex 的 Agent 智能体技能(Skills)自动化 ESP32 与 MQTT 通信的代码生成过程。我们首先分析了 IoT 开发的痛点,然后详细设计了 Skill 的输入配置,并分别提供了 MicroPython 和 C++ 两种语言的完整代码实现。通过对比两种语言的优缺点,帮助开发者根据项目需求选择合适的语言。最后,我们提供了详细的运行指南,确保开发者能够快速上手。Skill 设计哲学。

yueyeguzhuo的专栏 87

Windows10下安装VMware16虚拟机

由于本人系统为Windows 10 家庭中文版,无法安装Linux子系统WSL,虽然网上也有强制安装的方法,但为保险起见,还是把之前的VMware虚拟机重新进行安装,并浅浅记录一下安装过程。

沉香best的博客 868

Codeforces Round #478 (Div. 2) B Mancala

BMancalaB. Mancalatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMancala is a game famous in the Middle East. It is played on a board that consist...

howell 468

15、SQL Server查询优化与CPU负载管理

本文深入探讨了SQL Server查询优化与CPU负载管理的关键技术,包括强制连接类型的使用、键查找问题的解决、索引设计的最佳实践、高CPU负载的排查与优化,以及并行性的利弊与调整策略。通过优化查询逻辑、合理设计索引、监控与管理CPU资源,可以显著提升SQL Server的性能和稳定性。适用于数据库开发人员和DBA进行性能调优参考。

pz8901234的博客 82

Codeforces Round #478 (Div. 2) B. Mancala

B. MancalaMancala 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 conta...

s540239976的博客 330

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Codeforces Round #478 (Div. 2) 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 ...

gtuif的博客 241

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

B. Mancala (Codeforces Round #478 (Div. 2))

1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 14; 4 typedef long long ll; 5 ll a[maxn]; 6 ll b[maxn]; 7 8 int main(){ 9 for(int i =0 ;i < maxn;i...

weixin_30354675的博客 140

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #478 (Div. 2)B. Mancala(模拟)

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 ...

不二君 306

Codeforces Round #340 (Div. 2)

这场的codeforces异常简单 几乎没有什么算法题//虽然codeforces一直如此,想法题多于算法题 A签到题 B我的思路一开始很正确: 数连续出现的0的个数(夹在两个1中间才有效) 最后把这个连续0的个数都加1然后乘起来就是结果//就是高中数学中挡板问题 但是在做的时候出现了一点小纰漏 就是没考虑只有夹在两个1中间的连续的0是有效的 不然 0001100

is_it_a_error的博客 362

Codeforces Round #478 (Div. 2) ABC

A. Aramic script In Aramic language words can only represent objects. Words in Aramic have special properties: A word is arootif it does not contain the same letter more than once...

weixin_30641465的博客 124

Codeforces Round #478 Div2 975A 975B 975C 975D

A. Aramic script 题目大意: 对于每个单词,定义一种集合,这个集合包含且仅包含单词中出现的字母。给你一堆单词,问有多少种这种集合。 题解: 状压,插入set,取size #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring&gt...

weixin_30381317的博客 165

B. Mancala

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 i

memory_qianxiao的博客 792

Mancala

题目描述 Mancala is a family of board games played around the world, sometimes called sowing games, or count-and-capture games, which describes the game play. One simple variant is a solitaire game called...

eazo的博客 541

Mancala(模拟)

MancalaMancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which ...

codeswarrior的博客 1176

Mancala CodeForces - 975B (水)

B. Mancalatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMancala is a game famous in the Middle East. It is played on a board that consists of 14 ...

JiaYao的博客 428
上一篇: C++ STL set用法小结
下一篇: C/C++程序计时函数
_dingzhen
博客等级 码龄9年 120粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址