【题目链接】:http://codeforces.com/contest/785/problem/C

【题意】



容量为n的谷仓,每一天都会有m个谷子入仓(满了就视为m);第i天

会有i只鸟叼走i个谷子;

问哪一天谷仓最早变成空的了;

【题解】



当n<=m的时候,答案就为n;

当n>m的时候;

从第m+1天起谷仓的入库量比不上鸟的食量了;

会开始减少;

其中第m+1天减少m+1;

此后第m+2…依次减少2,3,4…

即首项为2公差为1的等差数列;

先让n减去m+1

然后让这个数列的和大于等于剩下的n时计算出项数x

则m+1+x就是答案了;

这里我在写二分的时候,上界弄小了,导致最后对于n=1e18,m=1的情况无法通过。

主要在于没注意到那个除2



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110; LL n, m, ans; void input_data()
{
cin >> n >> m;
} void get_ans()
{
if (n <= m)
{
ans = n;
return;
}
n -= (m + 1);
if (n <= 0)
{
ans = m + 1;
return;
}
LL l = 0, r = 2e9 + 2, t = 0;//hack点,r=1e18会爆LL
ans = m;
//首项是2
//2,3,4..x
//
while (l <= r)
{
LL mid = (l + r) >> 1;
LL temp = (mid + 2)*(mid - 1) / 2;
if (temp >= n)
{
t = mid;
r = mid - 1;
}
else
l = mid + 1;
}
ans += t;
} void o()
{
cout << ans << endl;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_data();
get_ans();
o();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 785C】Anton and Fairy Tale的更多相关文章

  1. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【13.77%】【codeforces 734C】Anton and Making Potions

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【81.37%】【codeforces 734B】Anton and Digits

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【77.39%】【codeforces 734A】Anton and Danik

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【25.00%】【codeforces 584E】Anton and Ira

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  8. 【codeforces 785E】Anton and Permutation

    [题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...

  9. 【codeforces 785D】Anton and School - 2

    [题目链接]:http://codeforces.com/contest/785/problem/D [题意] 给你一个长度为n的括号序列; 让你删掉若干个括号之后,整个序列变成前x个括号为左括号,后 ...

随机推荐

  1. jquery验证篇

    jquery验证:验证不了(包括easy ui 插件引用的js) jquery easy ui 引用的js <span style="color:#000000;">& ...

  2. Android底层开发之Linux输入子系统要不要推断系统休眠状态上报键值

    Android底层开发之Linux输入子系统要不要推断系统休眠状态上报键值 题外话:一个问题研究到最后,那边记录文档的前半部分基本上都是没用的,甚至是错误的. 重点在最后,前边不过一些假想猜測. ht ...

  3. Android Material风格的应用(二)--RecyclerView

    添加RecyclerView Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerViewAndro ...

  4. js进阶 13-8 jquery如何实现侧边栏

    js进阶 13-8 jquery如何实现侧边栏 一.总结 一句话总结:先是把侧边栏设置为left为-100px,隐藏起来,jquery自定义动画animate里面的改变元素的距左边的宽度left,sl ...

  5. TabControl控件重绘

    原文地址:http://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition 在网上看到重绘TabContr ...

  6. LeetCode Algorithm 07_Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...

  7. jmeter--十三种断言方式介绍

    jmeter中有个元件叫做断言(Assertion),它的作用和loadrunner中的检查点类似: 用于检查测试中得到的响应数据等是否符合预期,用以保证性能测试过程中的数据交互与预期一致. 使用断言 ...

  8. 自旋锁spinlock解析

    1 基础概念 自旋锁与相互排斥锁有点类似,仅仅是自旋锁不会引起调用者睡眠.假设自旋锁已经被别的运行单元保持.调用者就一直循环在那里看是否该自旋锁的保持者已经释放了锁."自旋"一词就 ...

  9. POJ 2402 Palindrome Numbers(LA 2889) 回文数

    POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...

  10. windows SID

    显示SID whoami /user 修改SID C:\windows\system32\sysprep\sysprep.exe /generalize /oobe /reboot