HDOJ-4004/(大连网赛1004)- The Frog's Games 二分答案+验证
2011-09-06 22:33
323 查看
题目在这里 http://acm.hdu.edu.cn/showproblem.php?pid=4004
以前我真的没怎么做过二分答案的。(鄙视我吧...)
显然这题的答案是一个单调序列,二分可以使复杂度为logn
代码:
以前我真的没怎么做过二分答案的。(鄙视我吧...)
显然这题的答案是一个单调序列,二分可以使复杂度为logn
代码:
//hdoj-4004 二分+验证 //1<= L <= 1000,000,000、0<= n <= 500,000、1<= m <= n+1 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define MAXN 500002 int l, n, m; int a[MAXN]; int check(int x) { int t = x; int cnt=0; for(int i=1; i<n+2; t=x) //点 { while(t>=a[i]-a[i-1]) // i 表示下一个要跳过的点。 { t-=a[i]-a[i-1]; i++; } cnt++; if(cnt>m) return 0; } return 1; } int main() { while(cin>>l>>n>>m) { a[0]=0; a[n+1]=l; for(int i=1; i<=n; i++) //n+2个点 { cin>>a[i]; } sort(a, a+n+2); //排序 int min=l%m? l/m+1: l/m; int max = l; while(min<max) // [min, max] { int mid = (min+max)/2; if(check(mid)) { max = mid; } else { min = mid+1; } } //当min=max 跳出 cout<<min<<endl; } }
相关文章推荐
- HDOJ-4004/(大连网赛1004)- The Frog's Games 二分答案+验证
- HDOJ 1004 Java 答案
- HDU/HDOJ 4004 2011大连赛区网络赛 D题
- HDU-4004 The Frog's Games 二分答案
- HDOJ 1004 Let the Balloon Rise(字符串)
- HDOJ 1004 java代码实现--引用相等要用 equals()
- hdoj 1004 Let the Balloon Rise
- HDOJ 1004 Let the Balloon Rise
- HDOJ--1004
- 渣渣ACM日记——1004-Let the Balloon Rise(HDOJ)
- HDOJ——简单题(1002,1004)
- 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保 配置指定了相同的 validationKey 和验证算法。不能在群集中使用 AutoGenerate(正确答案)
- [简单题][hdoj_1004]Let the Balloon Rise
- 大连某公司机试POSTGRESQL题目,个人回来后总结的答案
- hdoj1004
- HDOJ 1002.A+B Problem II 答案
- hdoj 验证角谷猜想 1266 (模拟)水
- HDOJ 1003.Max Sum 答案
- (HDOJ 1004)Let the Balloon Rise
- hdoj1004