【题目链接】: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. Excel 下拉菜单制作

    废话少说吧,以图明示: 图1 操作步骤(环境为Office 2013) 备注,第四步,可以选择页面中的数据源,也可以以“,”分割的方式输入字符串 图2 制作效果

  2. ORACLE使用WITH AS和HINT MATERIALIZE优化SQL解决FILTER效率低下

     在做项目的过程中,一个页面使用类似例如以下的SQL查询数据.为了保密和使用方便,我把项目中有关的表名和字段替换使用ORACLE数据库中的系统表和字段. 在我所做的项目中.类似ALL_TABLES ...

  3. 多线程在python中的使用 thread

    近期想学习研究一下python中使用多线程,来提高python在爬虫项目中的效率. 如今我们在网页上查询到在python中使用的多线程的使用大多数都是使用的threading模块,可是python中另 ...

  4. SQL server 错误代码对比表

    0  操作成功完毕.    1  功能错误.    2  系统找不到指定的文件.    3  系统找不到指定的路径.    4  系统无法打开文件.    5  拒绝訪问.    6  句柄无效.   ...

  5. 并发,one

    引言 最近工作当中写了一个有关并发的程序,引起了LZ对并发的强烈兴趣.这一下一发不可收拾,LZ用了一个多星期,看完了这本共280+页的并发编程书.之所以能看这么快,其实这主要归功于,自己之前对并发就有 ...

  6. 作为一个新人,怎样学习嵌入式Linux?(韦东山)

    这篇文章是引用韦老师的部分关于新人怎么学习嵌入式Linux的经验,引用如下: 1.电脑一开机,那些界面是谁显示的?是BIOS,它做什么?一些自检,然后从硬盘上读入windows,并启动它. 类似的, ...

  7. 硬件——STM32 , 录音,wav

    详细的wav头文件解析,有例子:http://www.cnblogs.com/chulin/p/8918957.html 关于录音程序的编写: 我的思路是改写原子的程序,原子的程序需要借助VS1053 ...

  8. Testfan软件测试社区

    1.  http://ask.testfan.cn/article/902  Appium 服务端安装-windows2.  http://ask.testfan.cn/article/1078 最新 ...

  9. 【Codeforces Round #442 (Div. 2) D】Olya and Energy Drinks

    [链接] 我是链接,点我呀:) [题意] 给一张二维点格图,其中有一些点可以走,一些不可以走,你每次可以走1..k步,问你起点到终点的最短路. [题解] 不能之前访问过那个点就不访问了.->即k ...

  10. 关于Altium Designer中的搜索图纸上的元件

    一开始以为Altium Designer搜索完成的pcb上的元件用ctrl+f 但是错了,应该是j,c