【玲珑】1106

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 (|Xi|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
1T,N1001≤T,N≤100 0R1000≤R≤100 1XN1≤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;
 } 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值