SDNU 1494.Problem_C

SDNU 1494.Problem_C

Time Limit: 1000 MS Memory Limit: 32768 KB
Total Submission(s): 52 Accepted Submission(s): 23
Description
ChaoChao, a lonely boy, has bought a Galaxy Note 7 and wants to destroy cities. There are N cities numbered 1… N on a line and each pair of adjacent cities has distance 1. Galaxy Note 7 has its explosion radius R. ChaoChao puts her Galaxy Note 7 in city X and city i will be destroyed if (|X−i|≤R).You must tell ChaoChao how many cities wil be destroyed.(viva Flaming Fire Force!!!)

Input
The first line contains a positive integer T, the number of test cases. Each of the following T lines contains three integers N, R, X.

1≤T,N≤100

0≤R≤100

1≤X≤N

Output
T lines.Each line contains one integer, the answer.

Sample Input
3
100 5 23
100 8 36
100 9 99

Sample Output
11
17
11

Source
Unknown

翻譯:
一個孤獨的男孩超超買了一臺Galaxy Note 7,他想摧毀城市。有N個編號爲1…N的城市在一條直線上,相鄰城市之間的距離都是1。Galaxy Note 7有其爆炸半徑R 。超超把Galaxy Note 7在城市X中。如果(|X−i|≤R),城市i將被摧毀。你一定要告訴超超多少城市將被摧毀。(火焰火焰萬歲!!!)

關愛空巢兒童啊!水題一道,唯一的坑點是如果R=0,應該輸出0。附上代碼:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        if(b==0)
            cout<<'0'<<endl;
        else if((a-c)<b&&c<=b)
            cout<<a<<endl;
        else if((a-c)<b&&c>b)
            cout<<a-c+b+1<<endl;
        else if((a-c)>b&&c<=b)
            cout<<b+c<<endl;
        else if((a-c)>b&&c>b)
            cout<<2*b+1<<endl;
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章