当前位置:网站首页>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 link
http://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】 【Example 2 output】 【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: 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: Then AC Beginners, please give more advice10 14 18
8

———————————————————————————————————————
#include
#include
边栏推荐
猜你喜欢
随机推荐
Synchronization lock synchronized traces the source
MySQL慢查询的多个原因
Blender程序化建模简明教程【PCG】
SecureCRT强制卸载
Solution: Edu Codeforces 109 (div2)
Xiaohei leetcode's refreshing rainy day trip, just finished eating Yufei Beef Noodles, Mala Tang and Beer: 112. Path Sum
random.normal() and random.truncated_normal() in TF
Ehrlich screening method: Counting the number of prime numbers
L3-2 Delete up to three characters (30 points)
STC8H开发(十五): GPIO驱动Ci24R1无线模块
几种绘制时间线图的方法
Easyui 表单验证「建议收藏」
Tensorflow中placeholder函数的用法
用户代码未处理MetadataException
CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
Cookie, session, token
5个 Istio 访问外部服务流量控制最常用的例子,你知道几个?
Converting angles to radians
2022 首期线下 Workshop!面向应用开发者们的数据应用体验日来了 | TiDB Workshop Day
In programming languages, the difference between remainder and modulo







