NOIP 2015 Senior 4
来源:互联网 发布:北京数据恢复培训 编辑:程序博客网 时间:2024/05/21 05:43
我就不说是题什么了,看了标题应该都懂。这道题就是一个二分答案,并写check函数。check时要用到贪心的思想:从前往后不用搬的石头就留着,能搬的石头就搬。但是这道题需要把最后一个石头也加进来进行相同的操作。可以证明,当得到答案时,最后一个石头一定没有被搬?不会证明?好吧,其实我也不会。因为这道题做过的,所以我就这么做了,但是正确性可能并不是很好证明。这时一定要多出数据,确保不要失误。
听说大犇都是10分钟写完程序,花50分钟用暴力程序对拍。如果有时间我也要学会这么做。。。
参考代码
#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <string>#include <stack>#include <queue>#include <deque>#include <map>#include <set>using std::cin;using std::cout;using std::endl;inline int readIn(){ int a; scanf("%d",&a); return a;}const int maxn = 50005;int l, n, m;int river[maxn];bool check(int interval){ int count_ = 0; int lastPos = 0; for(int i = 0; i <= n; i++) { if(river[i] - lastPos >= interval) { lastPos = river[i]; } else { count_++; } } return count_ <= m;}void run(){ l = readIn(); n = readIn(); m = readIn(); for(int i = 0; i < n; i++) { river[i] = readIn(); } river[n] = l; int left = 0, right = l; while(right - left > 1) { int mid = left + (right - left) / 2; if(check(mid)) { left = mid; } else { right = mid; } } if(check(right)) left++; printf("%d\n", left);}int main(){ run(); return 0;}
阅读全文
0 0
- NOIP 2015 Senior 4
- NOIP 2015 Senior 2
- NOIP 2015 Senior 3
- NOIP 2015 Senior 5
- NOIP 2015 Senior 6
- NOIP 2009 Senior 4
- NOIP 2011 Senior 4
- NOIP 2013 Senior 4
- NOIP 2016 Senior 4
- NOIP 2008 Senior 4
- NOIP 2007 Senior 4
- NOIP 2009 Senior 1
- NOIP 2009 Senior 3
- NOIP 2011 Senior 2
- NOIP 2011 Senior 3
- NOIP 2011 Senior 5
- NOIP 2011 Senior 6
- NOIP 2012 Senior 2
- 如何在ViewPager中的各个Fragment间传递数据并刷新Fragment界面?
- 我们为什么要使用AOP?
- hiho-1014 Trie树 (Trie的建树与查询)
- 如何在CSDN上加上一个自己的小栏目
- PyQt5简易入门指南01,环境的配置与搭建
- NOIP 2015 Senior 4
- 多项式求值,二维多项式,多项式乘法,多项式除法
- 关于Git中.gitignore文件失效问题
- TCP/IP协议入门(一)--阮一峰
- Git详解之五 分布式Git
- CPU指令解析
- github用gitbash上传代码
- 哈希算法
- python if __name__=='__main__'教程及原理