HDU——5037——Frog
2015-11-10 19:48
330 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5037
贪心,一个月没做题了,这道题卡了半天0 0~
只要考虑清楚走两个时,为了保证最优,使得距离要是L+1,如果小于这个值,会导致能直接走到这里,就不是最优了
题目要求最差情况下青蛙走的最佳情况,所以每次开始都使他只走1,然后走N
贪心,一个月没做题了,这道题卡了半天0 0~
只要考虑清楚走两个时,为了保证最优,使得距离要是L+1,如果小于这个值,会导致能直接走到这里,就不是最优了
题目要求最差情况下青蛙走的最佳情况,所以每次开始都使他只走1,然后走N
#include <cstdio> #include <algorithm> using namespace std; const int MAXN = 2e5 + 10; int main() { int N, M, L; int T; int a[MAXN]; scanf("%d", &T); int cas = 1; while(T--){ scanf("%d%d%d", &N, &M, &L); a[N+1] = M; for(int i = 1; i <= N; i++) scanf("%d", &a[i]); sort(a + 1 , a + N + 2); int pre = L, now = 0; int cnt = 0; int flag = 1; for(int i = 1; i <= N + 1; i++){ int len = a[i] - now; if(len == 0) continue; if(len + pre <= L){ pre = len + pre; now = a[i]; } else if(len <= L){ now = a[i]; pre = len; cnt++; } else{ // printf("%d %d\n", now, cnt); int k1, k2; k1 = len % (L+1); k2 = (len - k1)/(L+1); cnt += k2*2; if(k1 + pre <= L){ pre = k1 + pre; now = a[i]; } else { pre = k1; now = a[i]; cnt++; } } } printf("Case #%d: %d\n",cas++, cnt); } return 0; }
相关文章推荐
- 文章标题
- PHP开发环境——Zend Studio 12.5.1(64位)破解汉化
- sicily 9456 Clumsy Cows
- android杂项记录
- 【C#/算法】任意圆形和三角形相交部分面积的计算方法
- Redis之跳跃表SkipList
- android两种方式生成keystore
- man .info .--help的用法和区别
- html5中关于音频--视频的播放
- instanceType和id的异同
- java线程的学习
- 录音计时的TimeView
- c++从入门到实践
- 贤者时间太久了么?--MySQL继续玩
- 如何赚取人生的第一桶金
- MVC 学习 区域
- sicily 9162 RAZLIKA
- 【JMeter】软件测试中JMeter和Ant实现自动负载测试
- leetcode-Balanced Binary Tree
- 详细介绍WSDL文档