poj 2368 Buttons
来源:互联网 发布:软件购销合同书范本 编辑:程序博客网 时间:2024/06/05 05:56
题目链接:http://poj.org/problem?id=2368View Code
题意:巴什博奕,两人轮流从一堆中拿取按钮,最后一个拿完的赢。给出一个K,表示总共有K个按钮,然后求一个L,表示每次最多拿L个,使得后手赢。(L范围是2~K-1)若无则输出0,若有多个则输出最小的。
分析:巴什博奕公式为若K%(L+1)==0,则后手赢,因为后手可以一直维持这个必胜态,使得一轮里加起来拿的总数为l+1,最后总有的拿。又因为要求最小的,所以就是求K的大于2的最小因数,然后减去1;没有则输出0。(避免10,14类似情况)
代码:
#include<cstdio>#include<cmath>#include<cstring>#include<queue>#include<stack>#include<cstdlib>#include<iomanip>#include<string>#include<vector>#include<map>#include<string>#include<iostream>#include<algorithm>using namespace std;#define INF 0x3f3f3f3ftypedef long long ll;#define Max(a,b) (a>b)?a:b#define lowbit(x) x&(-x)int main(){ int n; scanf("%d",&n); int sum=n; for(int i=3; i*i<=n; i++) { if(n%i==0) { sum=i; break; } } if(sum==n) { if(n%2==0&&n/2>2) sum/=2; } sum--; if(sum<2) sum=0; printf("%d\n",sum); }
0 0
- Buttons(poj 2368)
- poj 2368 Buttons
- poj 2368 Buttons
- POJ-2368-Buttons [找规律]
- POJ 2368|URAL 1023|Buttons|博弈论
- 【巴什博奕】poj 2369 Buttons
- POJ 2368(Buttons) 巴什博弈变形 Java
- Buttons
- ExtJS buttons
- B. Buttons
- poj2368 Buttons
- POJ2368 Buttons
- Two Buttons
- Two Buttons
- Two Buttons
- Android-Buttons
- Radio Buttons
- Toggle Buttons
- poj 2365 Rope
- Hive分析窗口函数(五) GROUPING SETS,GROUPING__ID,CUBE,ROLLUP
- poj 2366 Sacrament of the sum
- poj 2367 Genealogical tree
- Apple Mach-O Linker (ld) Error Group
- poj 2368 Buttons
- poj 2369 Permutations
- poj 2370 Democracy in danger
- jmeter通过jmeter-plugins、jconsole对系统资源进行监控
- poj 2371 Questions and answers
- poj 2372 D++ Again
- HDU 5857 Median (2016 多校训#10 1001)
- HDU 5858 Hard problem (2016 多校训练#10 1002)
- HDU 5867 Water problem (2016 多校训练#10 1011)