关闭

zoj1003 Crashing Balloon

标签: algorithmc
1096人阅读 评论(3) 收藏 举报
分类:
  1. //zoj1003 Crashing Balloon
  2. //Accepted 1003 C++ 00:00.06 440K
  3. #include <stdio.h>
  4. #include <algorithm>
  5. using namespace std;
  6. int pa,pb,winner;
  7. void dfs(int a, int b, int n)
  8. {
  9.        if (b==1) {
  10.               if (a==1) winner = pa;
  11.               else winner = pb;//when A>1, asure A is mutiple of B(B==1)
  12.        }
  13.        if (n<=100) {//search form 2 to 100
  14.               if (winner!=pa){//B must challenge A, otherwise A win
  15.                      if (a%n==0) dfs(a/n,b,n+1);
  16.                      if (b%n==0) dfs(a,b/n,n+1);
  17.                      dfs(a,b,n+1);
  18.               }
  19.        }                  
  20. }
  21. void solve()
  22. {
  23.        if (pa==pb) {printf ("%d/n",pa); return;}
  24.        if (pa<pb) swap(pa,pb);//play1>play2
  25.        winner = 0;
  26.        dfs(pa,pb,2);
  27.        if (winner==0) winner = pa;
  28.        printf ("%d/n",winner);
  29. }
  30. int main()
  31. {
  32. #ifdef ONLINE_JUDGE
  33. #else
  34.        freopen("1003.txt","r",stdin);
  35. #endif
  36.        while (scanf ("%d %d",&pa,&pb) != EOF)
  37.               solve();
  38. #ifdef ONLINE_JUDGE
  39. #else
  40.        fclose(stdin);
  41. #endif
  42.       return 0;
  43. }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36773次
    • 积分:664
    • 等级:
    • 排名:千里之外
    • 原创:33篇
    • 转载:0篇
    • 译文:0篇
    • 评论:10条
    文章分类
    最新评论