1106 - Niro plays Galaxy Note 7
Time Limit:1s Memory Limit:128MByte
Submissions:329Solved:197
DESCRIPTION
Niro, a lovely girl, 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. Niro puts her Galaxy Note 7 in city X and city i will be destroyed
if (|X−i|≤R)(|X−i|≤R).You must tell Niro how many cities wil be destroyed.
INPUT
The first line contains a positive integer
TT, the number of test cases.Each of the following
TT lines contains three integers
NN,
RR,
XX.
OUTPUT
TT 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
HINT
1≤T,N≤1001≤T,N≤100
0≤R≤1000≤R≤100
1≤X≤N1≤X≤N
SOLUTION
覆盖点的个数
code:
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,x,r;int num;
scanf("%d%d%d",&n,&r,&x);
int a=min(n,x+r);
int b=max(1,x-r);
printf("%d\n",a-b+1);
}
return 0;
}
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,x,r;int num;
scanf("%d%d%d",&n,&r,&x);
if(n-x>=r){
if(x-1>=r) num=2*r+1;
else num=r+1+x-1;
}
else{
if(x-1>=r) num=r+1+n-x;
else num=n-x+x-1+1;
}
printf("%d\n",num);
}
return 0;
}
Niro与Galaxy Note7的城市摧毁计划

8912

被折叠的 条评论
为什么被折叠?



