【CPE】一顆星選集(Part 8) | C++

更新於 發佈於 閱讀時間約 5 分鐘

Square Numbers

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2456

中文題目:https://zerojudge.tw/ShowProblem?problemid=d186

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int a, b;
    while (cin >> a >> b && a + b){
        int n1 = sqrt(a);
        int n2 = sqrt(b);
        if (n1*n1 != a) n1++;
        cout << n2 - n1 + 1 << "\n";
    }
    return 0;
}

B2-Sequence

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2004#google_vignette

中文題目:https://zerojudge.tw/ShowProblem?problemid=d123

#include <iostream>
using namespace std;
#define maxn 20005

int main() {
    int n, Case = 1;
    while (cin >> n) {
        int b[n], sum[maxn];
        for (int i = 0; i < n; i++) {
            cin >> b[i];
        }
        for (int i = 0; i < maxn; i++) {
            sum[i] = 0;
        }
        bool flag = true;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                int x = b[i] + b[j];
                if (sum[x]) {
                    flag = false;
                    break;
                } else {
                    sum[x] = 1;
                }
            }
            if (!flag) break;
        }
        if (flag) cout << "Case #" << Case++ << ": It is a B2-Sequence.\n\n";
        else cout << "Case #" << Case++ << ": It is not a B2-Sequence.\n\n";
    }
    return 0;
}

Back to High School Physics

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1012#google_vignette

中文題目:https://zerojudge.tw/ShowProblem?problemid=d226

#include <iostream>
using namespace std;

int main() {
    int v, t;
    while (cin >> v >> t){
        cout << 2 * v * t << "\n";
    }
    return 0;
}
留言
avatar-img
留言分享你的想法!
avatar-img
Jim的沙龍
1會員
31內容數
Jim的沙龍的其他內容
2025/08/14
Odd Sum 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem&problem=1724 中文題目:https://zerojudge.tw/Sh
2025/08/14
Odd Sum 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=19&page=show_problem&problem=1724 中文題目:https://zerojudge.tw/Sh
2025/08/14
What is the Probability!! 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=997 中文題目:https:
2025/08/14
What is the Probability!! 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=997 中文題目:https:
2025/08/14
TeX Quotes 題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=208 中文題目:https://zerojudge.t
2025/08/14
TeX Quotes 題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=208 中文題目:https://zerojudge.t
看更多