ZeroJudge:2010-12-22 資訊社考試 (b004)*********************** 第 1 題 *********************** //b004: 繩子上吃草的牛 by Snail #include #include #include using namespace std; int main () { double D, L, r1, r2, area, PI=acos(-1.); while (cin >> D >> L) { r1 = L / 2; //長軸 r2 = sqrt (L*L - D*D) / 2; //短軸 area = PI * r1 * r2; //area--面積 cout << fixed << setprecision(3) << area << endl; } } (b080)*********************** 第 2 題 *********************** //b080: A. 畢氏定理(NPSC 2007 國中組決賽) by Snail #include #include using namespace std; int main () { int a, b, c, c2; //c2 (c^2)--c 平方 while (cin >> a >> b, a) { c2 = a*a + b*b; //假設a, b 為兩股 c = (int)sqrt(double(c2)); if (c2 == c*c) //如果a,b,c 是直角三角形 cout << c << endl; else { if (a < b) swap (a, b); //確使a 為斜邊 c2 = a*a - b*b; c = (int)sqrt(double(c2)); if (c2 == c*c) //如果a,b,c 是直角三角形 cout << c << endl; else cout << "Wrong\n"; } } } (b197)*********************** 第 3 題 *********************** //b197: B. 下雨天(NPSC 2008 國中組初賽) by Snail #include #include using namespace std; int main () { int n, x1, y1, x2, y2, s, tc, i, mini; double l, c, minc; //c(ost)--單位雨量的價格 cin >> tc; while (tc--) { cin >> n; minc = 1e100; //min c(ost)--最低價格 for (i=1; i<=n; i++) { cin >> x1 >> y1 >> x2 >> y2 >> s; l = sqrt( double((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))); c = s * l / abs(x1-x2); //l(ength)--遮雨棚長度 if (c < minc) mini = i, minc = c; //min i(ndex)--最低價格索引 } cout << mini << endl; } } (b226)*********************** 第 4 題 *********************** //b226: E. 鋪地磚(NPSC 2008 國中組決賽) by Snail #include using namespace std; int main () { int L, W, x, y; while (cin >> L >> W >> x >> y, L) { cout << ((L%x || W%y) && (L%y || W%x) ? -1 : (L * W) / (x * y)) << endl; } //若直擺不行 橫擺也不行 小屋面積 / 磁磚面積 } (d189)*********************** 第 5 題 *********************** //11150 - Cola (by Snail) #include using namespace std; int main() { int n; while (cin >> n) cout << n * 3 / 2 << endl; //等比級數r = 3 } (b225)*********************** 第 6 題 *********************** //b225: D. 棒球練習 (NPSC 2008 國中組決賽) by Snail #include using namespace std; int main () { int n, x1, y1, x2, y2, x3, y3; cin >> n; while (n--) { cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; cout << ((x2-x1)*(y3-y1) == (x3-x1)*(y2-y1) ? "NO\n" : "YES\n"); } //若斜率相等則不成一個三角形 } (d122)*********************** 第 7 題 *********************** //d122: Oh! My Zero!! (by Snail) #include using namespace std; int main () { int n, z; while (cin >> n) { z = 0; //z(eros)--零的個數 while (n /= 5) z += n; cout << z << endl; } }