CF 1187A - Stickers and Toys

本文探讨了在不确定KinderSurprise巧克力蛋中玩具和贴纸分布的情况下,如何计算购买最少数量的蛋以确保获得至少一个玩具和一个贴纸的策略。通过分析不同情况下的最优解,提供了一个算法解决方案。

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

A. Stickers and Toys

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Your favorite shop sells nn Kinder Surprise chocolate eggs. You know that exactly ss stickers and exactly tt toys are placed in nn eggs in total.

Each Kinder Surprise can be one of three types:

  • it can contain a single sticker and no toy;
  • it can contain a single toy and no sticker;
  • it can contain both a single sticker and a single toy.

But you don't know which type a particular Kinder Surprise has. All eggs look identical and indistinguishable from each other.

What is the minimum number of Kinder Surprise Eggs you have to buy to be sure that, whichever types they are, you'll obtain at least one sticker and at least one toy?

Note that you do not open the eggs in the purchasing process, that is, you just buy some number of eggs. It's guaranteed that the answer always exists.

Input

The first line contains the single integer TT (1≤T≤1001≤T≤100) — the number of queries.

Next TT lines contain three integers nn, ss and tt each (1≤n≤1091≤n≤109, 1≤s,t≤n1≤s,t≤n, s+t≥ns+t≥n) — the number of eggs, stickers and toys.

All queries are independent.

Output

Print TT integers (one number per query) — the minimum number of Kinder Surprise Eggs you have to buy to be sure that, whichever types they are, you'll obtain at least one sticker and one toy

Example

input

Copy

3
10 5 7
10 10 10
2 1 1

output

Copy

6
1
2

Note

In the first query, we have to take at least 66 eggs because there are 55 eggs with only toy inside and, in the worst case, we'll buy all of them.

In the second query, all eggs have both a sticker and a toy inside, that's why it's enough to buy only one egg.

In the third query, we have to buy both eggs: one with a sticker and one with a toy.

思路:题目要求你买的鸡蛋个数必须保证玩具和贴纸的个数各自大于一。也就是说在买的时候要尽可能多的买。举个例子比如上述类型鸡蛋个数分别为3,4,10。那么你这时候的要买的个数是5个。如果你买10个鸡蛋里面有贴纸和玩具。但是这不符合题目最少的要求。那你如果买3个那不符合题目要求贴纸和玩具各自大于一。所以应该买4+1个。为啥加1很简单。

下面加上代码

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long n,s,t;
        scanf("%lld%lld%lld",&n,&s,&t);
        long long num=s+t;
        long long k=num-n;
        s-=k;
        t-=k;
        ///printf("k==%lld s==%lld t==%lld\n",k,s,t);
        if(k==n)
        {
            puts("1");
        }
        else
        {
                long long num1=max(s,t);
                printf("%lld\n",num1+1);


        }

    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值