二分。

如果$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的更多相关文章

  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. Hadoop 遇到的问题集

    1. Mac 使用ssh命令无法成功 ssh localhost,但是可以ssh其他的 可能原因:ssh服务未启动 解决方法: 1.启动sshd服务: sudo launchctl load -w / ...

  2. 数学&动态规划:期望DP

    BZOJ3036 给定一张有向无环图,起点为1,终点为N,每个点i有ki条出边,从每个点走其中一条出边的概率是1/ki,求从1到N的期望步数 我们注意到一点,走每条边都是等概率的,那么就相当于 给定一 ...

  3. Flying to the Mars

    D - Flying to the Mars Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I ...

  4. Javascript动态绑定

    <div onclick="test()"></div> <script> function test(){ //code } </scr ...

  5. 为什么需要 Stream

    Stream 作为 Java 8 的一大亮点,它与 java.io 包里的 InputStream 和 OutputStream 是完全不同的概念.它也不同于 StAX 对 XML 解析的 Strea ...

  6. Oracle解锁scott账户

    Oracle安装完成之后scott账户默认是锁定的,登录的时候会提示账户已经被锁定: C:\Users\CC11001100>sqlplus scott/toor SQL*Plus: Relea ...

  7. Fiddler 断点调试http请求

    fiddler有两种断点,Before Requests(可以修改请求参数).After Responses(可以修改返回值) Before Requests 断点 1.设置Before Reques ...

  8. php webshell常见函数

    0x1 直接在字符串变量后面加括号, 会调用这个函数: <?php $s = 'system'; $e = 'assert'; $s('whoami'); $e('phpinfo();'); 0 ...

  9. python算法之近似熵、互近似熵算法

    理论基础 近似熵? 定义:近似熵是一个随机复杂度,反应序列相邻的m个点所连成折线段的模式的互相近似的概率与由m+1个点所连成的折线段的模式相互近似的概率之差. 作用:用来描述复杂系统的不规则性,越是不 ...

  10. WebBrowser中运行js

    HtmlElement script = wf.WebBrowser.Document.CreateElement("script"); script.SetAttribute(& ...