随笔分类 -  二分-三分

摘要:链接:http://poj.org/problem?id=2110最近几天一直做二分,感觉有点上手,但是碰见新题还是迷茫,就比如这个,没想起来怎么去用二分枚举答案,看了别人的代码才知道的。唉,还是要多练习啊View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 105 4 #define max(a,b) a>b?a:b 5 #define minx(a,b) a<b?a:b 6 int f[N][N]; 7 bool used[N][N]; 8 int dir[4][2]={{0,1}, 阅读全文
posted @ 2012-05-08 20:48 zhenhai 阅读(226) 评论(0) 推荐(0)
摘要:链接:http://poj.org/problem?id=297601分数规划,有一个序列ai,和一个序列bi,从中取出下标相等的m个数,使得∑a[i]/∑b[i]最大,刚开始用dp做的,TLE了,看了别人的题解,二分View Code 1 #include<stdio.h> 2 #include<math.h> 3 #include<stdlib.h> 4 #define N 1005 5 #define eps 1e-2 6 double a[N],b[N]; 7 double val[N]; 8 int cmp(const void *a,const 阅读全文
posted @ 2012-05-07 22:56 zhenhai 阅读(149) 评论(0) 推荐(0)
摘要:链接:http://poj.org/problem?id=3104二分答案,对于进行枚举的答案,如果自然风干的时间比其要短,那就让它自然风干,否则就保证一个物体占用甩干机的时间最短,即为(time[i]-t)/(k-1)View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #define N 100005 5 using namespace std; 6 int time[N]; 7 int n,k; 8 bool check(int t) 9 {10 int i;11 阅读全文
posted @ 2012-05-07 21:30 zhenhai 阅读(341) 评论(0) 推荐(0)
摘要:链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1390这道题,真的挺厉害,虽然用到的东西都不难,但是考察了很多方面,树状数组和二分,这个全用到了,并且还要记录是否访问过View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define N 100005 4 int a[N]; 5 int used[N]; 6 int n; 7 int lowbit(int x) 8 { 9 return x&am 阅读全文
posted @ 2012-05-02 22:46 zhenhai 阅读(224) 评论(0) 推荐(0)
摘要:poj 3273-Monthly Expense链接:http://poj.org/problem?id=3273这样的在最优情况下找最短时间的题一般都可以二分,当然还可以dp,但是因为本题的数据较大,dp会很耗时,也会很费空间,所以用二分的方法,从max(a[i])到sum(a[i])进行逼近。View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define MAX 305 4 int v[MAX]; 5 int main() 6 { 7 int n,m; 8 int sum,max; 9 int i;10 .. 阅读全文
posted @ 2012-04-06 22:00 zhenhai 阅读(152) 评论(0) 推荐(0)
摘要:hdoj 4004-The Frog's Games链接http://acm.hdu.edu.cn/showproblem.php?pid=4004这道题是11年大连赛区网络赛的一道题,当时刚刚学ACM没做出来,现在在看看,百感交集啊,只能说自己当时太水了。解释在代码的注释中View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 int stone[500005]; 5 int s,l; 6 int cmp(const void *a,const void * 阅读全文
posted @ 2012-04-05 21:34 zhenhai 阅读(225) 评论(0) 推荐(0)