关闭

zoj1005 Jugs

734人阅读 评论(0) 收藏 举报

Ca与Cb互质,已经保证有解,解有多种,Special Judge不一定要和Sample一致

  1. //zoj1005 Jugs
  2. //Accepted 1005 C++ 00:00.01 392K
  3. #include <stdio.h>
  4. int ca,cb,n;
  5. void solve()
  6. {
  7.        int a,b,bnow;
  8.        a = b = 0;
  9.        while (b != n){
  10.               for (int i=0; i<=(cb-b)/ca; ++i){
  11.                      printf ("fill A/n");
  12.                      printf ("pour A B/n");
  13.                      bnow = b+ca;
  14.                      if (bnow == n) {
  15.                             printf ("success/n");
  16.                             return;
  17.                      }
  18.               }
  19.               printf ("empty B/n");
  20.               printf ("pour A B/n");
  21.               a = ca-(cb-b)%ca;
  22.               b = a;
  23.               if (b == n) break;
  24.        }
  25.        printf ("success/n");
  26. }
  27. int main()
  28. {
  29. #ifdef ONLINE_JUDGE
  30. #else
  31.        freopen("1005.txt","r",stdin);
  32. #endif
  33.        while (scanf("%d %d %d",&ca,&cb,&n)!=EOF)
  34.               solve();
  35. #ifdef ONLINE_JUDGE
  36. #else
  37.        fclose(stdin);
  38. #endif
  39.        return 0;
  40. }
0
0

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