当前位置:网站首页>One Pass 2074: [21CSPJ Popularization Group] Candy

One Pass 2074: [21CSPJ Popularization Group] Candy

2022-08-09 23:44:00 Bamboo Forest Lay-

Title

Original title linkicon-default.png?t=M666http://ybt.ssoier.cn:8088/problem_show.php?pid=2074[Title Description]

Children at Red Sun Kindergarten are starting to distribute candy!

There are n children in Red Sun Kindergarten, and you are one of them.It is guaranteed that n≥2.

One day you found an infinite number of candies in the back garden of the kindergarten. You plan to take some candies back and distribute them to the children in the kindergarten.

Because you are just an ordinary kindergartener, your physical strength is limited, and you can only go back with R lumps at most.

But you don't get enough points, so you should at least take L candy back.It is guaranteed that n≤L≤R.

That is, if you take k candies, then you need to ensure that L≤k≤R.

If you take k pieces of candy, you will put the k pieces of candy in the basket and ask everyone to divide the candy according to the following scheme: As long as there are no less than n pieces of candy in the basket, all n children in the kindergarten (including yourself) take exactly one piece of sugar from the basket until there are fewer than n pieces of sugar in the basket.The rest of the candy in the basket is yours at this point—they are your reward for moving the candy.

As a high-quality kindergartener, you want to make the number of candies as a reward for moving candy (not the total number of candies you end up getting!) as much as possible; so you need to write a program that enters n, L,R, and output the maximum number of candies you can get as a reward for moving candies.

[Enter]

Enter a line containing three positive integers n, L, R, which represent the lower and upper bounds of the number of children and the number of candies, respectively.

[Output]

Print one line with an integer indicating the maximum number of candies you can get as a reward for carrying candies.

[Sample input]

7 16 23

[Example output]

6

[Tips]

【Explanation of Example 1】

Put k=20 candies in the basket.

The number of candies in the basket is now 20≥n=7, so all children get a piece of candy;

The number of candies in the basket now becomes 13≥n=7, so all children get a piece of candy;

The number of candies in the basket is now 6

It is easy to find that the number of candies you get as a reward for moving candies cannot exceed 6 pieces (otherwise, the number of candies in the basket is still no less than n at the end, and each child needs to continue to take one piece), so the answer is6.

【Sample 2 input】

10 14 18

【Example 2 output】

8

【Example 2 Explanation】

It is easy to find that when the amount k of candy you take satisfies 14=L≤k≤R=18, after all the children get a piece of candy, the remaining k−10 pieces of candy will always be the candy as your reward for moving candynumber, so taking k=18 blocks is the optimal solution, and the answer is 8.

[Data Range]

———————————————————————————————————————

The person who asked this question is very kind, just give the test points directly, and you can get points by typing the form

The simplest idea is to enumerate in a loop, just take turns to judge.The code is as follows:

#includeusing namespace std;long long n,l,r,maxn=-1,s;int main(){cin>>n>>l>>r;for(int i=l;i<=r;i++){s=i%n;if(s>maxn) maxn=s;}cout<

I handed it in confidently, but...

After reading the title again, I understand.The evaluation machine runs 10 to the 6th power in one second, and the data range is up to 10 to the 9th power

Then thought of a way, all the answers are nothing more than two cases:

1. The remainder contains n-1 output n-1

2. The remainder does not contain n-1 output R÷n

How to judge whether n-1 is included?

If n-1 is included, the L÷n and R÷n quotients must be different.So I wrote the following code:

#includeusing namespace std;int n,l,r;int main(){cin>>n>>l>>r;if(l/n==r/n) cout<

Then AC

Beginners, please give more advice

原网站

版权声明
本文为[Bamboo Forest Lay-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091956459830.html