【Gym
来源:互联网 发布:狼牙军品专卖店一淘宝 编辑:程序博客网 时间:2024/06/15 17:35
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
Input
2
2
5
Output
second
first
题意 : 给出一行 1 * n 的格子,一开始全是白色的,你可以选择不大于 p <=[L / 2] (向上取整,L为当前连着的最大数量的白色格子)的质数(没有不大于 p 的质数时,p取 1)去填任意 p 个格子,问最后先手和后手,谁最后一个把格子填满
思路 : 模拟几个数会发现,只用在 n 等于 2 或 3 时后手会赢,其余都是先手赢
AC代码:
#include<cstdio>#include<cmath>#include<map>#include<cstring>#include<algorithm>using namespace std;const int MAX = 1e5 + 10;typedef long long LL;int main(){ int T; scanf("%d",&T); while(T--){ int n,a; scanf("%d",&a); if(a == 2 || a == 3) puts("second"); else puts("first"); } return 0;}
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- 卢卡斯定理
- DZNEmptyDataSet——空白数据集显示框架
- Eclipse打war包(maven项目)错误To see the full stack trace of the errors, re-run Maven with the -e switch
- DrawLayout侧拉
- 如何对你的linux服务器进行快捷管理
- 【Gym
- 回归方程代码
- 运行时异常和普通异常的区别
- LintCode_安排课程
- Minimal string CodeForces
- 贝叶斯判别法
- Java 集合(1)----- List Set Queue Map
- 求两个单向链表的交点
- 题目2:括号配对问题