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 ...
随机推荐
- python中添加日志记录到文件
1.实现python日志功能 2.只输出到文件,不输出到控制台 #encoding:utf-8 import logging from common import path_util logging_ ...
- 用循环链表实现Josephus问题
Josephus问题:设有n个人围坐在一个圆桌周围,现从第s个人开始报数,数到第m的人出列,然后从出列的下一个人重新开始报数,数到第m的人又出列.如此反复直到所有的人全部出列为止. 思路:构建一个没有 ...
- Grails里DOMAIN类的一对一,一对多,多对多关系总结及集成测试
终于干完这一章节,收获很多啊. 和DJANGO有类似,也有不同. User.groovy: package com.grailsinaction class User { String loginId ...
- 最小堆的两种实现及其STL代码
#include<cstdio> #include<iostream> #include<algorithm> #include<vector> boo ...
- mongodb之安装
前言 系统环境是CentOS,linux只支持64位版本 yum源安装 rpm包说明 mongodb-org-server 包含mongod进程,关联配置,初始化脚本mongodb-org-mongo ...
- mybatis原理流程
无论是用过的hibernate,mybatis,你都可以法相他们有一个共同点: 从配置文件(通常是XML配置文件中)得到 sessionfactory. 由sessionfactory 产生 ses ...
- 查看Linux的CPU信息,核数等
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...
- 软件project文档中的数据库模型设计
背景:软件project文档之<数据库设计说明书>的结构设计部分要明白规划出数据库的概念结构设计.逻辑结构设计.物理结构设计,就是设计数据库的概念模型.逻辑模型.物理模型.那么.何为数据库 ...
- 用MJExtension简化MVC
首先引入MJExtension框架 模型 #import <Foundation/Foundation.h> @interface FundsModel : NSObject /** * ...
- 计算cost--全表扫描
以下教大家怎样手工算出oracle运行计划中的cost值. 成本的计算方式例如以下: Cost = ( #SRds * sreadtim + #MRds * mreadti ...