二分。

如果$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. vue-router的link样式设置问题

    发现router-link添加上去后文字上会出现下划线,打开调试工具发现router-link其实是由a来实现的,在reset的时候 a { text-decoraction: none; } 至于点 ...

  2. Mybatis多参数及实体对象传递

    在使用Mybatis的时候,经常会有各种各样的参数传递,不同类型,不同个数的参数. 先上个例子:     public List<LifetouchRelease> findOfficeL ...

  3. 目前最快速的多线程Kmeans算法,java实现

    目前最快速Kmeans算法,并由java实现!面对很大的K值表现依然很好. 代码地址: https://github.com/Jethu1/fastKmeans #1.这是一个由java实现的的,多线 ...

  4. 【Android】完善Android学习(七:API 4.0.3)

    备注:之前Android入门学习的书籍使用的是杨丰盛的<Android应用开发揭秘>,这本书是基于Android 2.2API的,目前Android已经到4.4了,更新了很多的API,也增 ...

  5. 2017国庆 清北学堂 北京综合强化班 Day1

    期望得分:60+ +0=60+ 实际得分:30+56+0=86 时间规划极端不合理,T2忘了叉积计算,用解析几何算,还有的情况很难处理,浪费太多时间,最后gg 导致T3只剩50分钟,20分钟写完代码, ...

  6. codevs 2796 最小完全图

    2796 最小完全图 http://codevs.cn/problem/2796/  时间限制: 1 s  空间限制: 128000 KB     题目描述 Description 若一个图的每一对不 ...

  7. bzoj 3622 DP + 容斥

    LINK 题意:给出n,k,有a,b两种值,a和b间互相配对,求$a>b$的配对组数-b>a的配对组数恰好等于k的情况有多少种. 思路:粗看会想这是道容斥组合题,但关键在于如何得到每个a[ ...

  8. 集合框架小结-List

    List集合存储的元素是有序的,可重复的,有索引 List特有方法: 增加 add(index, element); addAll(index, Collection); 删除 remove(inde ...

  9. python设计模式之单例模式(一)

    前言 单例模式是创建模式中比较常见和常用的模式,在程序执行的整个生命周期只存在一个实例对象. 系列文章 python设计模式之单例模式(一) python设计模式之常用创建模式总结(二) python ...

  10. python基础===将Flask用于实现Mock-server

    from flask import Flask from flask import request, Response, jsonify import random import string app ...