hdu4484 Hailstone HOTPO ——水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4484

题目思路:

  直接模拟即可

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 using namespace std;
 6 int cal(int n) {
 7   int Max = n;
 8   while (n!=1) {
 9     if ((n&1) == 0) {
10       n /= 2;
11     } else {
12       n = n * 3 + 1;
13     }
14     if (n > Max) Max = n;
15   }
16   return Max;
17 }
18 void solve() {
19   int n; scanf("%d", &n);
20   int i, t, ca;
21   for (i = 0; i < n; ++i) {
22     scanf("%d%d", &t, &ca);
23     int ans = cal(ca);
24     printf("%d %d\n", t, ans);
25   }
26 }
27 int main(void) {
28   //freopen("4484.in", "r", stdin);
29   solve();
30   return 0;
31 }

水题……

posted on 2013-03-10 16:21  aries__liu  阅读(369)  评论(0编辑  收藏  举报