close

題目連結:  https://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=50114

題目大意: 給你一個座標點,算出到圓心距離,並計算分數

思路1: 可用迴圈 i = 1 ~ 9,檢查是否符合距離i,符合即輸出答案 10-i

思路2: 直接數學,用10去減你的距離-1(無條件捨去),就是分數

代碼:

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int m;
    double o1 = 10.0, o2 = 10.0, x, y;
    cin >> m;
    while(m--){
        cin >> x >> y;
        double dis = sqrt((x - o1) * (x - o1) + (y - o2) * (y - o2));
        if(dis != 0.0 && dis == int(dis)){
            dis--;
        }
        if(dis > 9){
            cout << 0 << endl;
            continue;
        }
        cout << 10 - (int)dis << endl;
    }
    return 0;
}

arrow
arrow
    創作者介紹
    創作者 尾玉 的頭像
    尾玉

    louisfghbvc的部落格

    尾玉 發表在 痞客邦 留言(0) 人氣()