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;
}