# ACM-ICPC 寒假练习 05

## UVaOJ 113

  1 2 3 4 5 6 7 8 9 10 11 12  #include #include using namespace std; int main() { double x, y; while(cin >> x >> y) { cout << (int)floor(pow(y, 1 / x) + 0.5) << endl; } return 0; } 

## UVaOJ 10161

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22  #include #include using namespace std; int main() { int N; while(cin >> N) { if(N == 0) { break; } int k = ceil(sqrt(N)); int s = (k - 1) * (k - 1); int d = N - s; int x, y; if(d <= k) { x = d; y = k; } else { x = k; y = 2 * k - d; } if(k & 1) { swap(x, y); } cout << x << " " << y << endl; } return 0; } 

## UVaOJ 253

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34  #include #include #include using namespace std; const int MAX = 4; bool pVisited[MAX]; int main() { string x; while(cin >> x) { int nCnt = 0; memset(pVisited, false, sizeof(pVisited)); for(int i = 1; i <= 3; i++) { for(int j = 1; j <= 3; j++) { if((x[i - 1] == x[5 + j] && x[6 - i] == x[12 - j] || x[i - 1] == x[12 - j] && x[6 - i] == x[5 + j]) && !pVisited[j]) { nCnt++; pVisited[j] = true; break; } } } cout << (nCnt == 3 ? "TRUE" : "FALSE") << endl; } return 0; } 

## UVaOJ 621

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  #include #include using namespace std; int main() { int N; string x; while(cin >> N) { cin.ignore(); for(int i = 1; i <= N; i++) { getline(cin, x); if(x == "1" || x == "4" || x == "78") { cout << "+" << endl; } else if(x.substr(x.length() - 2, 2) == "35") { cout << "-" << endl; } else if(x[0] == '9' && x[x.length() - 1] == '4') { cout << "*" << endl; } else if(x.substr(0, 3) == "190") { cout << "?" << endl; } } } return 0; } 

## UVaOJ 10025

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  #include using namespace std; int main() { int T, K; cin >> T; for(int i = 1; i <= T; i++) { cin >> K; if(K < 0) { K = -K; } int nSum = 0; for(int j = 1; ; j++) { nSum += j; if(nSum >= K && (nSum - K) % 2 == 0) { cout << j << endl; break; } } if(i != T) { cout << endl; } } return 0; } 

## UVaOJ 591

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  #include using namespace std; const int MAX = 64; int pData[MAX]; int main() { int N, nCase = 0; while(cin >> N) { if(N == 0) { break; } int nSum = 0, ans = 0; cout << "Set #" << ++nCase << endl; for(int i = 1; i <= N; i++) { cin >> pData[i]; nSum += pData[i]; } nSum /= N; for(int i = 1; i <= N; i++) { if(pData[i] > nSum) { ans += pData[i] - nSum; } } cout << "The minimum number of moves is " << ans << "." << endl; cout << endl; } } 

## UVaOJ 107

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32  #include #include using namespace std; int main() { double H, C; while(cin >> H >> C) { if(H == 0 && C == 0) { break; } int x, y; if(C == 1) { x = ceil(log(H) / log(2)); y = 2 * H - 1; } else { int N; for(N = 1; N < H; N++) { if(fabs(log(H) * log(N) - log(C) * log(N + 1)) < 1E-8) { break; } } x = (C - 1) / (N - 1); y = (N + 1) * H - C * N; } cout << x << " " << y << endl; } return 0; } 

## UVaOJ 573

• 上爬的衰减因子只与第一次上爬的距离有关；
• 当上爬的距离小于0时，蜗牛不再上爬。
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  #include using namespace std; int main() { double H, U, D, F; while(cin >> H >> U >> D >> F) { if(H == 0) { break; } F /= 100.0; int nDay = 0; double dNow = 0, dUp = U; while(1) { nDay++; dNow += dUp; dUp -= F * U; if(dNow > H) { cout << "success on day " << nDay << endl; break; } if(dUp < 0) { dUp = F = 0; } dNow -= D; if(dNow < 0) { cout << "failure on day " << nDay << endl; break; } } } return 0; } 

## UVaOJ 846

1195
22106
33116
43126
54137
64147
75157
85167

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  #include #include using namespace std; int main() { int T, x, y; cin >> T; for(int i = 1; i <= T; i++) { cin >> x >> y; int d = y - x; if(d == 0) { cout << "0" << endl; } else { int s = (int)(sqrt(d * 1.0)); if(s * s == d) { s = 2 * s - 1; } else if(s * (s + 1) < d) { s = 2 * s + 1; } else { s *= 2; } cout << s << endl; } } return 0; } 

## UVaOJ 10499

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  #include using namespace std; int main() { long long N; while(cin >> N) { if(N < 0) { break; } long long nPercent = N * 25; if(N == 1) { nPercent = 0; } cout << nPercent << "%" << endl; } return 0; } 

## UVaOJ 10790

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  #include using namespace std; int main() { int nCase = 0; long long x, y; while(cin >> x >> y) { if(x == 0 && y == 0) { break; } long long ans = x * (x - 1) * y * (y - 1) / 4; cout << "Case " << ++nCase << ": " << ans << endl; } return 0; } 

## UVaOJ 11044

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  #include #include using namespace std; int main() { int T, W, H; cin >> T; for(int i = 1; i <= T; i++) { cin >> W >> H; int x = (W - 2) / 3 + ((W - 2) % 3 != 0); int y = (H - 2) / 3 + ((H - 2) % 3 != 0); cout << x * y << endl; } return 0; } 

## UVaOJ 10719

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45  #include #include #include #include using namespace std; const int MAX = 10240; int pData[MAX], pAns[MAX]; int main() { int k; string x; while(cin >> k) { memset(pData, 0, sizeof(pData)); memset(pAns, 0, sizeof(pAns)); int nCnt = 0, nPos = 1, r = 0; cin.ignore(); getline(cin, x); istringstream iss(x); while(iss >> pData[++nCnt]); nCnt--; while(nPos < nCnt) { if(pData[nPos] != 0) { pAns[nPos] = pData[nPos]; pData[nPos] = 0; pData[nPos + 1] += k * pAns[nPos]; } nPos++; } if(pData[nPos]) { r = pData[nPos]; } cout << "q(x):"; for(int i = 1; i < nPos; i++) { cout << " " << pAns[i]; } cout << endl; cout <<"r = " << r << endl; } return 0; } 

## UVaOJ 10177

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  #include using namespace std; int main() { long long N; while(cin >> N) { long long s2 = (N * (N + 1) * (2 * N + 1)) / 6; long long s3 = (N * (N + 1) / 2) * (N * (N + 1) / 2); long long s4 = (N * (N + 1) * (2 * N + 1) * (3 * N * N + 3 * N - 1)) / 30; long long r2 = (N * (N + 1) / 2) * (N * (N + 1) / 2) - s2; long long r3 = (N * (N + 1) / 2) * (N * (N + 1) / 2) * (N * (N + 1) / 2) - s3; long long r4 = (N * (N + 1) / 2) * (N * (N + 1) / 2) * (N * (N + 1) / 2) * (N * (N + 1) / 2) - s4; cout << s2 << " " << r2 << " " << s3 << " " << r3 << " " << s4 << " " << r4 << endl; } return 0; } 

## UVaOJ 10916

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  #include #include using namespace std; int main() { int N; while(cin >> N) { if(N == 0) { break; } int k = (N - 1960) / 10 + 2; double dSum = 0.0; for(int i = 1; ; i++) { dSum += log(i) / log(2); if(dSum > (1 << k)) { cout << i - 1 << endl; break; } } } return 0; } 

## UVaOJ 10970

$$\mathrm{ans} = xy - 1$$

  1 2 3 4 5 6 7 8 9 10 11  #include using namespace std; int main() { int x, y; while(cin >> x >> y) { cout << x * y - 1 << endl; } return 0; } 

## UVaOJ 10014

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  #include #include using namespace std; int main() { int T, N; double s, e; cin >> T; for(int i = 1; i <= T; i++) { double ans = 0, dTmp; cin >> N; cin >> s >> e; ans = N * s + e; for(int j = 1; j <= N; j++) { cin >> dTmp; ans -= 2.0 * (N - j + 1) * dTmp; } cout << fixed << setprecision(2) << ans / (N + 1) << endl; if(i != T) { cout << endl; } } return 0; }