当前位置:网站首页>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 linkhttp://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
边栏推荐
- 肝通宵写了三万字把SQL数据库的所有命令,函数,运算符讲得明明白白讲解,内容实在丰富,建议收藏+三连好评!
- 为什么这么多人都想当产品经理?
- TRUNCATE表之后空间未释放
- Converting angles to radians
- Pagoda measurement - building LightPicture open source map bed system
- laravel table migration error [easy to understand]
- AI+医疗:使用神经网络进行医学影像识别分析
- Leetcode 93 复原IP地址
- 接口自动化测试实践指导(上):接口自动化需要做哪些准备工作
- L3-2 至多删三个字符 (30 分)
猜你喜欢
随机推荐
CVPR22 Oral | shunt through multi-scale token polymerization from attention, code is open source
JSON 基本使用
蔚来杯2022牛客暑期多校训练营7 CFGJ
Cookie, session, token
APP automation test framework - UiAutomator2 introductory
抽象类 or 接口
MLOps的演进历程
TF生成均匀分布的tensor
np中的round函数,ceil函数与floor函数
[Generic Programming] Full Detailed Explanation of Templates
LeetCode26:删除有序数组中的重复项
金山云地震,震源在字节?
STC8H开发(十五): GPIO驱动Ci24R1无线模块
Leetcode 93 复原IP地址
【测试】语句覆盖,判定覆盖,条件覆盖,路径覆盖
编译原理之文法
5个 Istio 访问外部服务流量控制最常用的例子,你知道几个?
STC8H development (15): GPIO drive Ci24R1 wireless module
Basic operations of openGauss database (super detailed)
Multiple reasons for MySQL slow query