“
A -- Niro plays Galaxy Note 7
Time Limit:1s Memory Limit:128MByte
Submissions:333Solved:199
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 integerTT, 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
3100 5 23100 8 36100 9 99
SAMPLE OUTPUT
111711
HINT
1≤T,N≤1001≤T,N≤1000≤R≤1000≤R≤1001≤X≤N1≤X≤N
SOLUTION
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
int main()
{
int n,i,t,r,x;
scanf("%d",&t);
while(t--)
{
int sum=0;
scanf("%d%d%d",&n,&r,&x);
for(i=1;i<=n;i++)
{
if(fabs(x-i)<=r)
sum++;
}
printf("%d\n",sum);
}
return 0;
}