二分。

如果$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. 2017北京国庆刷题Day3 afternoon

    期望得分:100+0+30=130 实际得分:100+36.5+0=136.5 T3 一个变量写混了,丢了30.. 模拟栈 #include<cstdio> #include<cst ...

  2. 拓扑排序 最大字典序+优先队列 BZOJ 4010

    http://www.lydsy.com/JudgeOnline/problem.php?id=4010 4010: [HNOI2015]菜肴制作 Time Limit: 5 Sec  Memory ...

  3. 「七天自制PHP框架」应用:JSON生成器

    刚刚开始学做一个WebAPP,数据查询的一般套路是通过一张PHP页面读取数据库,获得列表后“嵌写”在PHP页面中,虽然写法上丑陋至极,但也有“快糙猛”出效果的成就感,如图. 后来想想,不对啊,难道以后 ...

  4. 【费用流】【CODEVS】1227 方格取数2

    [算法]最小费用最大流(费用流) [题解] 费用流:http://www.cnblogs.com/onioncyc/p/6496532.html 本题构图: 在有限的k次行走中尽可能多的拿到数字,明显 ...

  5. 线程池-Threadlocal

    ThreadLoclc初衷是线程并发时,解决变量共享问题,但是由于过度设计,比如弱引用的和哈希碰撞,导致理解难度大.使用成本高,反而成为故障高发点,容易出现内存泄露,脏数据.贡献对象更新等问题.单从T ...

  6. 用jquery实现小火箭到页面顶部的效果

    恩,不知道之前在哪看过一个页面效果就是如果页面被滑动了就出现一个小火箭,点击这个小火箭就可以慢慢回到页面顶部,闲的没事,自己搞了一下 需要引入jquery 代码和布局都很简单 <!DOCTYPE ...

  7. NYOJ 756 重建二叉树 (二叉树)

    题目链接 描述 题目很简单,给你一棵二叉树的后序和中序序列,求出它的前序序列(So easy!). 输入 输入有多组数据(少于100组),以文件结尾结束.每组数据仅一行,包括两个字符串,中间用空格隔开 ...

  8. APP爬虫之Appium使用

    一.安装环境 Appium安装(windows版) 一.安装node.js 1.到官网下载node.js:https://nodejs.org/en/download/ 2.获取到安装文件后,直接双击 ...

  9. php常用表单验证类用法实例

    <?php /** * 页面作用:常用表单验证类 * 作 者:欣然随风 * QQ:276624915 */ class class_post { //验证是否为指定长度的字母/数字组合 func ...

  10. 设计模式之Adapter

    设计模式总共有23种模式这仅仅是为了一个目的:解耦+解耦+解耦...(高内聚低耦合满足开闭原则) 介绍: 将两个不兼容的类纠合在一起使用,属于结构型模式,也有人称它为wrapper(包装类). 包装类 ...