二分。

如果$n≤m$,显然只能$n$天。

如果$n>m$,至少可以$m$天,剩余还可以支撑多少天,可以二分计算得到,也可以推公式。二分计算的话可能爆$long$ $long$,上了个$Java$。

  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main
  5. {
  6. static Scanner cin = new Scanner(System.in);
  7.  
  8. static BigInteger sum(BigInteger L,BigInteger R)
  9. {
  10. if(L.compareTo(R)>0) return BigInteger.ZERO;
  11. BigInteger A = L.add(R);
  12. BigInteger B = R.subtract(L); B = B.add(BigInteger.ONE);
  13. BigInteger c = A.multiply(B);
  14. return c.divide(BigInteger.valueOf(2));
  15. }
  16.  
  17. public static void main(String []args)
  18. {
  19. BigInteger m,n;
  20.  
  21. n = cin.nextBigInteger();
  22. m = cin.nextBigInteger();
  23.  
  24. if(n.compareTo(m)<=0)
  25. {
  26. System.out.println(n);
  27. }
  28.  
  29. else
  30. {
  31. BigInteger ans = m;
  32. BigInteger sy = n.subtract(m);
  33.  
  34. BigInteger hai = BigInteger.ZERO;
  35.  
  36. BigInteger L = BigInteger.ZERO, R = sy;
  37.  
  38. boolean pp=false;
  39. while(L.compareTo(R)<=0)
  40. {
  41. BigInteger mid = (L.add(R).divide(BigInteger.valueOf(2)));
  42. if(sum(ans.add(BigInteger.ONE),ans.add(mid)).compareTo(sy.add(m.multiply(mid)))<0)
  43. {
  44. pp=true;
  45. hai = mid;
  46. L = mid.add(BigInteger.ONE);
  47. }
  48.  
  49. else if(sum(ans.add(BigInteger.ONE),ans.add(mid)).compareTo(sy.add(m.multiply(mid)))==0)
  50. {
  51. pp=false;
  52. hai = mid;
  53. L = mid.add(BigInteger.ONE);
  54. }
  55.  
  56. else R = mid.subtract(BigInteger.ONE);
  57. }
  58.  
  59. ans = ans.add(hai);
  60.  
  61. if(pp == true) ans = ans.add(BigInteger.ONE);
  62. System.out.println(ans);
  63.  
  64. }
  65.  
  66. }
  67. }

CodeForces 785C Anton and Fairy Tale的更多相关文章

  1. CodeForces 785C Anton and Fairy Tale 二分

    题意: 有一个谷仓容量为\(n\),谷仓第一天是满的,然后每天都发生这两件事: 往谷仓中放\(m\)个谷子,多出来的忽略掉 第\(i\)天来\(i\)只麻雀,吃掉\(i\)个谷子 求多少天后谷仓会空 ...

  2. 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 ...

  3. 【codeforces 785C】Anton and Fairy Tale

    [题目链接]:http://codeforces.com/contest/785/problem/C [题意] 容量为n的谷仓,每一天都会有m个谷子入仓(满了就视为m);第i天 会有i只鸟叼走i个谷子 ...

  4. 【二分】Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale

    当m>=n时,显然答案是n: 若m<n,在第m天之后,每天粮仓减少的量会形成等差数列,只需要二分到底在第几天,粮仓第一次下降到0即可. 若直接解不等式,可能会有误差,需要在答案旁边扫一下. ...

  5. C. Anton and Fairy Tale

    链接 [https://codeforces.com/contest/785/problem/C] 题意 初始时有n,第1天先加m开始吃1,但总的不能超过n,第i天先加m开始吃i(如果不够或刚好就吃完 ...

  6. C. Anton and Fairy Tale(数学推式子)

    \(数学题,式子并不难推,但边界是真的烦\) \(\color{Red}{Ⅰ.其实可以发现,当m>=n时,每次都可以粮食补到n,所以一定是在第n天消耗完毕}\) \(\color{Purple} ...

  7. 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 ...

  8. Codeforces 734E. Anton and Tree 搜索

    E. Anton and Tree time limit per test: 3 seconds memory limit per test :256 megabytes input:standard ...

  9. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

随机推荐

  1. [DeeplearningAI笔记]卷积神经网络3.6-3.9交并比/非极大值抑制/Anchor boxes/YOLO算法

    4.3目标检测 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.6交并比intersection over union 交并比函数(loU)可以用来评价对象检测算法,可以被用来进一步改善对 ...

  2. 洛谷 U3357 C2-走楼梯

    https://www.luogu.org/problem/show?pid=U3357 题目背景 在你成功地解决了上一个问题之后,方方方不禁有些气恼,于是他在楼梯上跳来跳去,想要你求出他跳的方案数. ...

  3. 给你灵感!21个精美的 iOS APP 网站设计欣赏

    iOS 吹起了轰轰烈烈的扁平化设计风格,而做为承载 App 宣传重任的网页,整体设计风格的变迁如何?是否也如iOS的设计风格改革一样彻底的翻转?还是如往常一直深耕成熟的设计风格? Spendee Fo ...

  4. FastDFS图片服务器java后台的简单调用

    工具类: package com.liveyc.common.fdfs; import org.apache.commons.io.FilenameUtils; import org.csource. ...

  5. 面试整理(3)js事件委托

    事件委托主要用于一个父容器下面有很多功能相仿的子容器,这时候就需要将子容器的事件监听交给父容器来做.父容器之所以能够帮子容器监听其原理是事件冒泡,对于子容器的点击在冒泡时会被父容器捕获到,然后用e.t ...

  6. sg函数&&子状态的讨论

    题目链接:https://cn.vjudge.net/contest/269933#problem/H 具体思路:首先,这是一个公平的比赛,并且是两个人参与,两个人都足够聪明,并且可以通过有限步结束比 ...

  7. document.write 简介

    document.write 的执行分两种情况: 第一种:dom加载已完成 1. 执行 document.open() (即会清空document) 2. 执行 document.write() 3. ...

  8. Linux实用命令之xdg-open

    为什么要介绍 xdg-open 呢,得先从需求说起. 一般在控制台中,可以使用命令操作各式文本文件.但难以避免,需要操作一些非文本文件,如 pdf,doc 等. 此时,一般的做法是,打开文件管理器,再 ...

  9. NOIP模拟赛 城市

    题目描述 $ZZQ$ 是一国之主. 这个国家有$N$个城市, 第$i$个城市与第$(i + 1) (mod N)$和$(i - 1) (mod N)$在一个正$N$边形相连. $ZZQ$ 又新建了$N ...

  10. 在html页面中引入公共的头部和底部

    参考链接: http://www.cnblogs.com/jason-star/p/3345225.html http://blog.csdn.net/jsxzzliang/article/detai ...