alwaysBeAStarter

博客园 首页 新随笔 联系 订阅 管理

题目链接:http://poj.org/problem?id=2368

Bash game (巴什博弈):当K是(L+1)的倍数时可以确保second player赢。所以这道题要找的就是在K的因子中有没有大于2的因子。代码如下:

 1 #include <iostream>
 2 #include <math.h>
 3 #include <stdio.h>
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <string.h>
 7 #include <string>
 8 #include <sstream>
 9 #include <cstring>
10 #include <queue>
11 #include <vector>
12 #include <functional>
13 #include <cmath>
14 #include <set>
15 #define SCF(a) scanf("%d", &a)
16 #define IN(a) cin>>a
17 #define FOR(i, a, b) for(int i=a;i<b;i++)
18 #define Infinity 999999999
19 #define NInfinity -999999999
20 #define PI 3.14159265358979323846
21 typedef long long Int;
22 using namespace std;
23 
24 int main()
25 {
26     int K;
27     int a;
28     int factor[10010];
29     while (SCF(K) != EOF)
30     {
31         int len = 0;
32         for (a = 1; a*a <= K; a++)
33         {
34             if (K % a == 0)
35             {
36                 factor[len++] = a;
37                 factor[len++] = K / a;
38             }
39         }
40         sort(factor, factor + len);
41         bool found = false;
42         FOR(i, 0, len)
43         {
44             if (factor[i] > 2)
45             {
46                 printf("%d\n", factor[i]-1);
47                 found = true;
48                 break;
49             }
50         }
51         if (!found)
52             printf("0\n");
53     }
54     return 0;
55 }

 

posted on 2017-06-27 00:32  alwaysBeAStarter  阅读(102)  评论(0编辑  收藏  举报