SDNU 1494.Problem_C

10 篇文章 0 订阅

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值