poj1740 A New Stone Game
题意:对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该堆剩余石子的一部分分给其它的某些堆。
真是好♂题,代码不长就是好♂题。
首先考虑两堆相同的石子,先手一定必输,因为若是我操作第一堆,则后手也可以对第二堆做对称决策。
其实,其他情况,一定是先手必胜。
第一种情况:奇数堆。
我们可以将最大堆的石子分配给其他堆让他们两两配对,如下图所示:

显然,红色部分绝壁不会超过第五个 石子的高度。
第二种情况:偶数情况
我们可以把最大堆和最小堆先配对,剩余的那段照样拿来和n-2堆石子配用。

呆玛:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
int n,f[],x;
int main(){
while (scanf("%d",&n)&&n){
int cnt=;
memset(f,,sizeof f);
for (int i=;i<=n;i++){
scanf("%d",&x);
if (!f[x]) cnt++,f[x]=;
else cnt--,f[x]=;
}
if (!cnt) printf("0\n");
else printf("1\n");
}
}
poj1740 A New Stone Game的更多相关文章
- poj1740 A New Stone Game[博弈]
有若干堆石子,每一次需要从一堆石子中拿走一些,然后如果愿意的话,再从这堆石子中拿一些(揣度题意应该是不能拿出全部)分给其它任意不为空的堆.不能操作的人为负. 一直不会博弈啊..感觉完全就是个智商题,虽 ...
- 博弈论之Nim
博弈论(一):Nim游戏 重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P-position当且仅当a1^a2^...^an=0,其中^表示位异或(xor)运算. Nim游戏是博 ...
- 博弈论BOSS
基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...
- 【Mark】博弈类题目小结(HDU,POJ,ZOJ)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...
- 【poj1740】 A New Stone Game
http://poj.org/problem?id=1740 (题目链接) 男人八题之一 题意 对于n堆石子,每堆若干个,两人轮流操作,每次操作分两步,第一步从某堆中去掉至少一个,第二步(可省略)把该 ...
- POJ1740A New Stone Game[组合游戏]
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5769 Accepted: 3158 ...
- timus 1180. Stone Game 解题报告
1.题目: 1180. Stone Game Time limit: 1.0 secondMemory limit: 64 MB Two Nikifors play a funny game. The ...
- HDU 4048 Zhuge Liang's Stone Sentinel Maze
Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/327 ...
- POJ 1740 A New Stone Game
A New Stone Game Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5453 Accepted: 2989 ...
随机推荐
- nova-network
nova network-create demo-net --bridge br100 --multi-host T --fixed-range-v4 192.168.3.0/26 192.168.3 ...
- mysql中的unique
distinct可以把重复的行去掉,查询时候用select distinct * from ...; unique在MySQL中是完整性约束里的一种,如果某列的值需要是唯一的那么就添加UNIQUE约束 ...
- iOS--创建uiscrollview
//创建uiscrollview self.PageHeight = self.view.bounds.size.height; self.PageWidth = self.view.bounds.s ...
- 【C#网络基础】C# get post请求
using KTCommon.Helper; using KTCommon.LOG; using System; using System.Collections.Generic; using Sys ...
- android中定位光标位置
edittext.setSelection(int); edittext.setText(123);//设置edittext中的内容 edittext.setSelection(123.length( ...
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- Swift中实现点击、双击、捏、旋转、拖动、划动、长按手势的类和方法介绍
1.UITapGestureRecognizer 点击/双击手势 代码如下: var tapGesture = UITapGestureRecognizer(target: self, action: ...
- [小技巧] Python 脚本暴力破解 HC2600 机顶盒管理密码
家里最近接入了广电有线电视,配了三个创维 HC2600 机顶盒,并且每个机顶盒还带有无线路由器功能. 免费赠送 Internet 接入服务倒也没什么,不过机顶盒内置的 WIFI 实在有点寒酸:只支持 ...
- Intent 意图 结构 简介
Intent简介 官方解释: An intent is an abstract description of an operation操作 to be performed展示.表演. It can b ...
- 浅述Oracle分布式事务概念
着系统的复杂性不断增加,我们所面对的分布式系统渐渐增加.分布式文件系统.分布式消息队列系统等等层出不穷,在一些行业特别是互联网行业应用广泛.分布式数据库也是目前使用比较常用的分布式系统之一. 简单来说 ...