hdu4484 Hailstone HOTPO ——水题

March 10, 2013
Hdu

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4484 题目思路:   直接模拟即可


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int cal(int n) {
  int Max = n;
  while (n!=1) {
    if ((n&1) == 0) {
      n /= 2;
    } else {
      n = n * 3 + 1;
    }
    if (n > Max) Max = n;
  }
  return Max;
}
void solve() {
  int n; scanf("%d", &n);
  int i, t, ca;
  for (i = 0; i < n; ++i) {
    scanf("%d%d", &t, &ca);
    int ans = cal(ca);
    printf("%d %d\n", t, ans);
  }
}
int main(void) {
  //freopen("4484.in", "r", stdin);
  solve();
  return 0;
}

水题……

comments powered by Disqus