HDU_1729_sg函数(dfs)
Stone Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3051 Accepted Submission(s):
939
follows:
1. There are n boxes; each box has its size. The box can hold up
to s stones if the size is s.
2. At the beginning of the game, there are some
stones in these boxes.
3. The players take turns choosing a box and put a
number of stones into the box. The number mustn’t be great than the square of
the number of stones before the player adds the stones. For example, the player
can add 1 to 9 stones if there are 3 stones in the box. Of course, the total
number of stones mustn’t be great than the size of the box.
4.Who can’t add
stones any more will loss the game.
Give an Initial state of the game.
You are supposed to find whether the first player will win the game if both of
the players make the best strategy.
Each
test case begins with an integer N, 0 < N ≤ 50, the number of the
boxes.
In the next N line there are two integer si, ci (0 ≤ ci ≤ si ≤
1,000,000) on each line, as the size of the box is si and there are ci stones in
the box.
N = 0 indicates the end of input and should not be
processed.
the first line, then output “Yes” (without quotes) on the next line if the first
player can win the game, otherwise output “No”.
Yes
No
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define N 1000005 int Sg(int c,int s)
{
int t=sqrt(s);
while(t*t+t>=s)
t--;
if(c>t)
return s-c;
else
return Sg(c,t);
} int main()
{
int n,cnt=;
while(scanf("%d",&n)!=EOF&&n)
{
int s,c,res=;
while(n--)
{
scanf("%d%d",&s,&c);
res^=Sg(c,s);
}
printf("Case %d:\n",++cnt);
if(res)
printf("Yes\n");
else
printf("No\n");
}
return ;
}
HDU_1729_sg函数(dfs)的更多相关文章
- 新疆大学ACM-ICPC程序设计竞赛五月月赛(同步赛)B 杨老师的游戏【暴力/next-permutation函数/dfs】
链接:https://www.nowcoder.com/acm/contest/116/B 来源:牛客网 题目描述 杨老师给同学们玩个游戏,要求使用乘法和减法来表示一个数,他给大家9张卡片,然后报出一 ...
- 黑白图像(DFS)
输入一个n*n的黑白图像(1表示黑色,0表示白色),任务是统计其中八连块的个数.如果两个黑格子有公共边或者公共顶点,就说它们属于同一个八连块.如图6-11所示的图形有3个八连块. 图6-11 拥有3 ...
- POJ 1321 棋盘问题(DFS板子题,简单搜索练习)
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44012 Accepted: 21375 Descriptio ...
- 广度优先(bfs)和深度优先搜索(dfs)的应用实例
广度优先搜索应用举例:计算网络跳数 图结构在解决许多网络相关的问题时直到了重要的作用. 比如,用来确定在互联网中从一个结点到另一个结点(一个网络到其他网络的网关)的最佳路径.一种建模方法是采用无向图, ...
- POJ 1321 - 棋盘问题 - [经典DFS]
题目链接:http://poj.org/problem?id=1321 Time Limit: 1000MS Memory Limit: 10000K Description 在一个给定形状的棋盘(形 ...
- 记忆化搜索(DFS)--How many ways
How many ways 这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m).游戏的规则描述如下:1.机器人一开始在棋盘的起始点并有起始点所标有的能量.2. ...
- bfs与dfs基础
bfs像二叉树的层序遍历 像这个图走bfs就{1, 2, 3, 4, 5, 6, 7, 8}这样走: dfs就{1, 2, 5, 6, 3, 7, 8, 4}. bfs与queue相结合,走到哪就把哪 ...
- 递归一题总结(OJ P1117倒牛奶)
题目: 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数,最初,A和B桶都是空的,而C桶是装满牛奶的.有时,约翰把牛奶从一个桶倒到另 ...
- ZOJ 2412 Farm Irrigation
Farm Irrigation Time Limit: 2 Seconds Memory Limit: 65536 KB Benny has a spacious farm land to ...
随机推荐
- Codeforces 263C. Appleman and Toastman
C. Appleman and Toastman time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Ch’s gift
Ch’s gift Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Proble ...
- MySQL的各种网络IO超时的用法和实现
2016-04-06 赵伟 数据库开发者 客户端C API 在C API中调用mysql_options()来设置mysql_init() 所创建的连接对象的属性,使用这三个选项可以设置连接超时和读写 ...
- springmvc 时间返回格式化
如果是@ResponseBody,可以通过@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")设置返回的样式: 如果是不是@ResponseBody ...
- VB.NET机房收费 & 抽象工厂模式
学习设计模式的时候,提到了一个专门訪问数据库的模式-抽象工厂模式,记得当时举样例理解的时候并未设计到数据库,仅仅是大概了了解了一下,如今对于机房收费系统涉及到了数据库的管理,借此机会好好学习一下.用常 ...
- [Algorithms] The Bayes Rule
Prior odd: The idea is to take the odds for something happening (against it not happening), which we ...
- 在CentOS VPS上源代码安装高版本号git
背景:个别软件在国内下载非常慢,在vps下载就非常快. 可是下载好后的文件通过scp弄出来的时候又非常慢,所以想通过在vps里安装git,通过gitlab或oschina来进行中转.但遗憾的是,上传到 ...
- Implementing Software Timers - Don Libes
在看APUE习题10.5的时候提示了这篇文章,讲的非常清晰,设计也非常巧妙,所以把原文放在这里.值得自己去实现. Title: Implementing Software Timers By ...
- Zepto Code Rush 2014-A. Feed with Candy(HACK)
A. Feed with Candy time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- AOP代理分析
一:代理 代理类和目标类实现了同样的接口.同样的方法. 假设採用工厂模式和配置文件的方式进行管理,则不须要改动client程序.在配置文件里配置使用目标类还是代理类,这样以后就非常easy切换.(比如 ...