二分。

如果$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. Python学习笔记(三十一)正则表达式

    ---恢复内容开始--- 摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000 ...

  2. 用django框架做自己的blog

    说明:我的系统环境是ubuntu 14.10版本的,整理这篇博客,主要是自己记性太不好了,老忘东西,教训一下自己.哈哈 参考文章 createing blog 1,part-1-creating-bl ...

  3. 【CODEVS】1033 蚯蚓的游戏问题

    [算法]网络流-最小费用最大流(费用流) [题解]与方格取数2类似 在S后添加辅助点S_,限流k 每条边不能重复走,限流1 #include<cstdio> #include<alg ...

  4. 【CodeForces】913 C. Party Lemonade

    [题目]C. Party Lemonade [题意]给定n个物品,第i个物品重量为2^(i-1)价值为ci,每个物品可以无限取,求取总重量>=L的最小代价.1<=30<=n,1< ...

  5. Razor使用Parse()时最好指定“缓存名”

    为什么? 本文的标题,明显有一种提醒的口吻. 从18年的生活经验看,如果想提醒人要怎么办,不要怎么办. 最好说明原因.那么小编开始说明原因喽. 哦对,说原因之前,先说交代一下背景,一句话 在非mvc下 ...

  6. three.js轨道控制器OrbitControls.js

    https://blog.csdn.net/qq_37338983/article/details/78575333 文章地址

  7. 摘: 给Shapre命名

    有两种解决方式: 在 VBA 中将slide中的Shape命名,改变shape.name即可. 另外一种方式就是有点投机取巧:你可以点击shap,右键选择web/alternativetext做些标记 ...

  8. s3c6410下移植sqlite3.7.8

    http://blog.chinaunix.NET/uid-30441-id-2133838.html 1.下载源代码http://www.sqlite.org/download.html 2.tar ...

  9. [转载]FFmpeg完美入门[4] - FFmpeg应用实例

    1 用FFserver从文件生成流媒体 一.安装ffmpeg 在ubuntu下,运行sudo apt-get ffmpeg 安装ffmpeg,在其他linux操作系统下,见ffmpeg的编译过程(编译 ...

  10. centos 下单独安装mysql

    https://www.cnblogs.com/running-mydream/p/4666094.html https://www.cnblogs.com/lzj0218/p/5724446.htm ...