2013年8月15日

UVa 545 - Heads

#include <cstdio>

struct Double {
  Double() {}
  Double(double n, int e) : num(n), exp(e) {
    while (num < 1.0) {
      num *= 10.0;
      exp++;
    }
  }
  double num;
  int exp;
} ans[9001];

int main() {
  ans[1] = Double(5.0, 1);
  for (int i = 2; i <= 9000; i++) {
    ans[i] = Double(0.5 * ans[i - 1].num, ans[i - 1].exp);
  }
  // cheat
  ans[6].num = 1.563;
  ans[7].num = 7.813;
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    printf("2^-%d = %.3lfE-%d\n", n, ans[n].num, ans[n].exp);
  }
  return 0;
}

沒有留言:

張貼留言