在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
题目连接:http://codeforces.com/contest/785/problem/C DescriptionAnton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..." More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of n grains was full. Then, every day (starting with the first day) the following happens: m grains are brought to the barn. If m grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account). InputThe only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018) — the capacity of the barn and the number of grains that are brought every day. OutputOutput one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one. Sample Input5 2 Sample Output4 Hint题意有一个最多装有n个粮食的粮仓,每天晚上会增加m的粮食,但是最多不超过n 然后第i天早上都会被麻雀吃掉i个粮食。 问你第几天,这个粮仓会被吃空。 题解:正面做比较难,于是我们就转化为判定性问题,二分来做。 首先显然前min(n,m)天是没用的,因为你吃了,晚上就会补回去。 那么从min(n,m)天开始,粮仓的上限也是没有用的了,因为你并不能补满。 然后我们就二分天数去做就好了,判断吃的,是否能够超过他补充的。 但是直接做会爆longlong,你得处理一下。 这里我们一开始都减去m,这样就没有超过longlong了。 代码
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论