“玲珑杯”ACM比赛 Round #12(A -- Niro plays Galaxy Note 7)

本文介绍了一个简单的算法问题,使用Galaxy Note 7模拟城市破坏范围。通过输入城市数量、爆炸半径及放置位置,计算受影响的城市总数。文章包含了一个C++实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值