zoj1003 Crashing Balloon

  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
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值