Gym - 101350E Competitive Seagulls (博弈)
There are two seagulls playing a very peculiar game. First they line up N unit squares in a line, all originally colored white.
Let L be the length of the longest continuous sub-segment of white unit squares. Let P be any prime that satisfies the condition that . The player can choose any P if it satisfies the conditions but if there is no value of P that does, then P is set to 1.
The current player then proceeds to choose any continuous sub-segment of white unit squares of length P and paint them black. The player who can’t make a move loses.
If both players play optimally and the first player starts, which player is going to win the game?
Input
The first line of input is T – the number of test cases.
Each test case contains a line with a single integer N (1 ≤ N ≤ 107).
Output
For each test case, output on a single line "first" (without quotes) if the first player would win the game, or "second" if the second would win.
Example
2
2
5
second
first 题意:
每次可以取一段白色连续区间内p个,把白的染成黑色。不能染色的玩家失败。
整段区间内,最长的白色连续区间的长度为L,p是小于等于L/2的任意质数,如果没有质数,p可以取1;
思路:
手推,2,3是先手必败,1是先手必胜。
大于3的偶数,在中间取2,使留下来的两段长度相等。
大于3的奇数,在中间取3,使留下来的两段长度相等。
然后就像nim博弈只有两堆石子那样,跟着第二个人取,就可以坐等胜利了。
#include<cstdio>
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
if(n==||n==){printf("second\n");}
else printf("first\n");
}
return ;
}
Gym - 101350E Competitive Seagulls (博弈)的更多相关文章
- 脑洞 博弈 E. Competitive Seagulls 2017 ACM Arabella Collegiate Programming Contest
题目链接:http://codeforces.com/gym/101350/problem/E 题目大意:给你一个长度为n的方格,方格上面都被染色成了白色.每次染色都是选择白色的,假设目前选择的这块白 ...
- Gym 100512F Funny Game (博弈+数论)
题意:给两个数 n,m,让你把它们分成 全是1,每次操作只能分成几份相等的,求哪一个分的次数最多. 析:很明显,每次都除以最小的约数是最优的. 代码如下: #pragma comment(linker ...
- 2017 ACM-ICPC EC-Final ShangHai 东亚洲大陆-上海
比赛链接:传送门 Gym 101775A Chat Group(签到:待补) Gym 101775B Scapegoat(待补) Gym 101775C Traffic Light(贪心+思维) 思路 ...
- 2017 ACM Arabella Collegiate Programming Contest(solved 9/13, complex 12/13)
A.Sherlock Bones 题意: 给出长度为n的01串,问f(i,j)=f(j,k),(i<j<k)的i,j,k取值种数.其中f(i,j)表示[i,j]内1的个数, 且s[j]必须 ...
- Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】
G. The jar of divisors time limit per test:2 seconds memory limit per test:64 megabytes input:standa ...
- Gym - 101246D 博弈
题意:一个无向有环的图,从 1 号结点起火,开始蔓延,两个绝顶聪明的人轮流走,谁不能走谁输,输出输的人: 分析: 当时知道是博弈,但是想当然的以为 1 号结点有一个奇数层,就必胜:其实不是这样的,当一 ...
- Gym - 101775L SOS 博弈 找规律
题目:https://cn.vjudge.net/problem/Gym-101775L PS:训练赛中被这道题折磨的不轻,和队友反复推必胜态与必败态试图推导出公式或者规律,然后推的心态逐渐失控,,, ...
- Gym 100827G Number Game (博弈)
Number Game Alice and Bob are playing a game on a line of N squares. The line is initially populated ...
- L - SOS Gym - 101775L 博弈
题目链接:https://cn.vjudge.net/contest/274151#problem/L 题目大意:给你一个1*n的方格,两个人轮流放字母,每一次可以放"S"或者&q ...
随机推荐
- SQLServer之修改表值函数
修改表值函数注意事项 更改先前通过执行 CREATE FUNCTION 语句创建的现有 Transact-SQL 或 CLR 函数,但不更改权限,也不影响任何相关的函数.存储过程或触发器. 不能用 A ...
- 面相服务的架构SOA
SOA体系结构是基于服务组件模型,将应用程序的不同功能单元通过定义良好的接口契约联系起来,接口是采用中立方式进行定义的,独立于实现服务的硬件平台,操作系统和编程语言.使得构建在这样的系统中的服务可以以 ...
- python3 判断数据类型
def estType(): eventList = [1, 'Tom', {'name': 'Lucy', 'age': 16, 'grade': 98}] print(type(eventList ...
- jQuery中toggle与slideToggle以及fadeToggle之间的不同
toggle()方法: 定义和用法 切换元素的可见状态.如果被选元素可见,则隐藏这些元素,如果被选元素隐藏,则显示这些元素. 语法: $(selector).toggle(speed,callback ...
- python之单元测试_生成测试报告
(1)HTMLTestRunner.py的下载路径:https://pan.baidu.com/s/1Yk2E8d8bIo5_rmpussOE9Q 提取码:0jae (2)HTMLTestRunner ...
- (一)走进Metasploit渗透测试框架
渗透测试的流程 渗透测试是一种有目的性的,针对目标机构计算机系统安全的检测评估方法,渗透测试的主要目的是改善目标机构的安全性.渗透测试各个阶段的基本工作: 1.前期交互阶段 在这个阶段,渗透测试工程师 ...
- Spring Boot 2.x 快速入门(下)HelloWorld示例详解
上篇 Spring Boot 2.x 快速入门(上)HelloWorld示例 进行了Sprint Boot的快速入门,以实际的示例代码来练手,总比光看书要强很多嘛,最好的就是边看.边写.边记.边展示. ...
- Django REST framework基础:版本控制
DRF的版本控制 为什么需要版本控制 API 版本控制允许我们在不同的客户端之间更改行为(同一个接口的不同版本会返回不同的数据). DRF提供了许多不同的版本控制方案. 可能会有一些客户端因为某些原因 ...
- Redis操作list
来自:http://www.cnblogs.com/alex3714/articles/6217453.html List操作,redis中的List在在内存中按照一个name对应一个List来存储. ...
- HBase工具:如何查看HBase的HFile
root@root:~/Desktop/sourceCodes/hbase-2.1.1/bin# ./hbase Usage: hbase [<options>] <command& ...