当前位置:   article > 正文

CD1611_天龙1611ud

天龙1611ud
  1. //没有想仔细,,WA了几次。还好,
  2. #include<iostream>
  3. #include<stdlib.h>
  4. #include<math.h>
  5. #include<stdio.h>
  6. #include<algorithm>
  7. #include<queue>
  8. #include<string.h>
  9. #include<stack>
  10. #include<math.h>
  11. #include<string>
  12. #include<stdlib.h>
  13. #include<list>
  14. #include<vector>
  15. using namespace std;
  16. int get(int a,int b)
  17. {
  18. if (a>b)
  19. swap(a,b);
  20. if (b%a==0)
  21. return a;
  22. return get(b%a,a);
  23. }
  24. int main()
  25. {
  26. int i,j,k;
  27. int t;
  28. scanf("%d",&t);
  29. while (t--)
  30. {
  31. scanf("%d%d",&i,&j);
  32. if (i<=j)
  33. {
  34. k=get(i,j);
  35. k=i+j-k;
  36. printf("%d\n",k);
  37. }
  38. else
  39. {
  40. k=get(i,j);
  41. k=j+i-k;
  42. printf("%d\n",k);
  43. }
  44. }
  45. }




训练士兵
Time Limit: 1000 ms Memory Limit: 65536 kB Solved: 93 Tried: 556
Description

    elfness正在玩一个游戏,在这个游戏里,他掌管着一个王国。

    这是一个回合制的游戏,初始的时候elfness没有任何钱,每一回合开始他会获得a的金钱,当elfness的金钱大于等于b时,elfness会花钱去训练士兵,直到他的钱小于b,每训练一个士兵需要花b的钱。训练完士兵后进入下一回合。elfness想知道他在整个游戏过程中他钱最多的时刻他有多少钱。
Input

输入的第一行是一个整数T(T<=10000), 表示有T组测试数据。
对于每组测试数据,有一行,包含两个整数A和B(1<=A,B<=10^9).
??
Output

对于每组测试数据,输出一个整数,表示elfness在钱最多的时刻有多少钱。
Simple Input

2
2 3
7 11
Simple Output

4
17
Hint

对于第一组样例,elfness拥有的金钱数将如下变化:0->2->4->1->3->0->......所以他最多时有4的金钱。
输入量很大,请用scanf代替cin进行输入。
Source
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/410125
推荐阅读
相关标签
  

闽ICP备14008679号