CodeForces 785C Anton and Fairy Tale
二分。
如果$n≤m$,显然只能$n$天。
如果$n>m$,至少可以$m$天,剩余还可以支撑多少天,可以二分计算得到,也可以推公式。二分计算的话可能爆$long$ $long$,上了个$Java$。
- import java.math.BigInteger;
- import java.util.Scanner;
- public class Main
- {
- static Scanner cin = new Scanner(System.in);
- static BigInteger sum(BigInteger L,BigInteger R)
- {
- if(L.compareTo(R)>0) return BigInteger.ZERO;
- BigInteger A = L.add(R);
- BigInteger B = R.subtract(L); B = B.add(BigInteger.ONE);
- BigInteger c = A.multiply(B);
- return c.divide(BigInteger.valueOf(2));
- }
- public static void main(String []args)
- {
- BigInteger m,n;
- n = cin.nextBigInteger();
- m = cin.nextBigInteger();
- if(n.compareTo(m)<=0)
- {
- System.out.println(n);
- }
- else
- {
- BigInteger ans = m;
- BigInteger sy = n.subtract(m);
- BigInteger hai = BigInteger.ZERO;
- BigInteger L = BigInteger.ZERO, R = sy;
- boolean pp=false;
- while(L.compareTo(R)<=0)
- {
- BigInteger mid = (L.add(R).divide(BigInteger.valueOf(2)));
- if(sum(ans.add(BigInteger.ONE),ans.add(mid)).compareTo(sy.add(m.multiply(mid)))<0)
- {
- pp=true;
- hai = mid;
- L = mid.add(BigInteger.ONE);
- }
- else if(sum(ans.add(BigInteger.ONE),ans.add(mid)).compareTo(sy.add(m.multiply(mid)))==0)
- {
- pp=false;
- hai = mid;
- L = mid.add(BigInteger.ONE);
- }
- else R = mid.subtract(BigInteger.ONE);
- }
- ans = ans.add(hai);
- if(pp == true) ans = ans.add(BigInteger.ONE);
- System.out.println(ans);
- }
- }
- }
CodeForces 785C Anton and Fairy Tale的更多相关文章
- CodeForces 785C Anton and Fairy Tale 二分
题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 ...
- Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 二分
C. Anton and Fairy Tale 题目连接: http://codeforces.com/contest/785/problem/C Description Anton likes to ...
- 【codeforces 785C】Anton and Fairy Tale
[题目链接]:http://codeforces.com/contest/785/problem/C [题意] 容量为n的谷仓,每一天都会有m个谷子入仓(满了就视为m);第i天 会有i只鸟叼走i个谷子 ...
- 【二分】Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale
当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. ...
- C. Anton and Fairy Tale
链接 [https://codeforces.com/contest/785/problem/C] 题意 初始时有n,第1天先加m开始吃1,但总的不能超过n,第i天先加m开始吃i(如果不够或刚好就吃完 ...
- C. Anton and Fairy Tale(数学推式子)
\(数学题,式子并不难推,但边界是真的烦\) \(\color{Red}{Ⅰ.其实可以发现,当m>=n时,每次都可以粮食补到n,所以一定是在第n天消耗完毕}\) \(\color{Purple} ...
- ural 1343. Fairy Tale
1343. Fairy Tale Time limit: 1.0 secondMemory limit: 64 MB 12 months to sing and dance in a ring the ...
- Codeforces 734E. Anton and Tree 搜索
E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
随机推荐
- [DeeplearningAI笔记]卷积神经网络3.6-3.9交并比/非极大值抑制/Anchor boxes/YOLO算法
4.3目标检测 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.6交并比intersection over union 交并比函数(loU)可以用来评价对象检测算法,可以被用来进一步改善对 ...
- 洛谷 U3357 C2-走楼梯
https://www.luogu.org/problem/show?pid=U3357 题目背景 在你成功地解决了上一个问题之后,方方方不禁有些气恼,于是他在楼梯上跳来跳去,想要你求出他跳的方案数. ...
- 给你灵感!21个精美的 iOS APP 网站设计欣赏
iOS 吹起了轰轰烈烈的扁平化设计风格,而做为承载 App 宣传重任的网页,整体设计风格的变迁如何?是否也如iOS的设计风格改革一样彻底的翻转?还是如往常一直深耕成熟的设计风格? Spendee Fo ...
- FastDFS图片服务器java后台的简单调用
工具类: package com.liveyc.common.fdfs; import org.apache.commons.io.FilenameUtils; import org.csource. ...
- 面试整理(3)js事件委托
事件委托主要用于一个父容器下面有很多功能相仿的子容器,这时候就需要将子容器的事件监听交给父容器来做.父容器之所以能够帮子容器监听其原理是事件冒泡,对于子容器的点击在冒泡时会被父容器捕获到,然后用e.t ...
- sg函数&&子状态的讨论
题目链接:https://cn.vjudge.net/contest/269933#problem/H 具体思路:首先,这是一个公平的比赛,并且是两个人参与,两个人都足够聪明,并且可以通过有限步结束比 ...
- document.write 简介
document.write 的执行分两种情况: 第一种:dom加载已完成 1. 执行 document.open() (即会清空document) 2. 执行 document.write() 3. ...
- Linux实用命令之xdg-open
为什么要介绍 xdg-open 呢,得先从需求说起. 一般在控制台中,可以使用命令操作各式文本文件.但难以避免,需要操作一些非文本文件,如 pdf,doc 等. 此时,一般的做法是,打开文件管理器,再 ...
- NOIP模拟赛 城市
题目描述 $ZZQ$ 是一国之主. 这个国家有$N$个城市, 第$i$个城市与第$(i + 1) (mod N)$和$(i - 1) (mod N)$在一个正$N$边形相连. $ZZQ$ 又新建了$N ...
- 在html页面中引入公共的头部和底部
参考链接: http://www.cnblogs.com/jason-star/p/3345225.html http://blog.csdn.net/jsxzzliang/article/detai ...