Buttons(poj 2368)
来源:互联网 发布:北京北大青鸟网络学校 编辑:程序博客网 时间:2024/06/05 01:55
poj2368:点击打开链接
写个简单的题……巴什博弈的扩展,输入石子数n,要求使后手能赢的最小的m值,其实就是找n % (m + 1) == 0的m的最小值,可以通过找n的因子,选择一个最小的减一即可。注意找因子的时间,没排序前a数组的前两个数是1和n,如果n是素数,那么答案就是n - 1,如果不是素数,那么就要排序,找出了1意外的n的最小因子。
#include <stdio.h>#include <algorithm>using namespace std;int a[10010];int main (void){int n;while(scanf("%d", &n) != EOF){int i;bool f = 0;int k = 0;for(i = 1; i * i <= n; i++){//i从1开始,如果n是素数,那么答案就是n - 1 if(n % i == 0){a[k ++] = i;a[k ++] = n / i;}}sort(a, a + k);//将因子从小到大排序 for(i = 0; i < k; i++)printf("%d ", a[i]);printf("\n");for(i = 0; i < k; i++){if(a[i] > 2){printf("%d\n", a[i] - 1);f = 1;break;}}if(f == 0)printf("0\n");}return 0;}
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
- [LeetCode] Letter Combinations of a Phone Number
- 在一个文件中有10G个整数,乱序排列,要求找出中位数
- 批量删除Windows7中隧道适配器的方法
- Distinct Subsequences
- Parallels 9 Activation:
- Buttons(poj 2368)
- 10006Carmichael Numbers
- HDU1881 - 毕业bg(背包大小会改变的01背包)
- [c.y.j]redis 错误提示
- cpanel添加不了域名的问题及解决
- MySQL数据库 一
- java开发之mysql的PreparedStatement
- asp.net中前台调用后台变量,C#后台调用前台jquery
- C/C++基础知识:typedef用法小结