zoj1005 Jugs

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. }
阅读更多
文章标签: c
个人分类: ZOJ
上一篇zoj1003 Crashing Balloon
下一篇zoj1010 Area
想对作者说点什么? 我来说一句

Jugs问题求解C++

2014年11月01日 19KB 下载

没有更多推荐了,返回首页

关闭
关闭