【題解】CPE 一顆星選集:20. Beat the Spread!

題目

s = sum, d = absolute difference
two final scores, largest first (or impossible)

UVa 連結
ZeroJudge 連結

解法

s = a + b
d = a – b
s + d = 2a
s – d = 2b

#include <iostream>
#define ll long long
using namespace std;

int main(){
    int S;
    ll D;
    while(cin >> S >> D){
        int now = S;
        while(D > 0){
            D -= now;
            if(D > 0) now++;
        }
        cout << now << 'n';
    }
}
👉 回到:【CPE大學程式能力檢定】目錄
發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *