上一页 1 ··· 160 161 162 163 164 165 166 167 168 ··· 182 下一页
摘要: 记忆化搜索,使用dfs,从0,0点开始,把每个点对应的剩下路程所能得到的最大值存入f数组。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <vector>#include <cmath>#include <queue>using namespace std;#define maxn 105int map[maxn][maxn];int f[maxn][maxn];int ans, 阅读全文
posted @ 2011-03-29 09:03 undefined2024 阅读(143) 评论(0) 推荐(0)
摘要: 用素数筛,枚举所有区间,把加和,并把ans对应的位+1.View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define maxn 10005bool is[maxn];int prm[maxn];int sum[maxn];int ans[maxn];int getprm(int n){ int i, j, k = 0; int s, e = (in 阅读全文
posted @ 2011-03-24 12:40 undefined2024 阅读(542) 评论(0) 推荐(0)
摘要: 题意:一个无向图,每条边有两个权值,c和l,要求一个生成树,使得所有边的c的和比上l的和最小。分析:最优比例生成树。现在要求(c1+...)/(l1+...),设一个比例值变量为r。令r>=(c1+...)/(l1+...)。现在题目转化为求r的最小值。假设我们对于一个确定的r可以判断该不等式是否可以满足,那么我们可以用二分查找的方法来求r的最小值,因为r猜大了则可满足,猜小了则不可满足。然而,我们确实可以对于一个确定的r来判定是否可满足不等式,方法如下:现在r是确定的,相当于已知r。先将不等式整理为如下形式:(r*l1-c1)+...>=0,然后我们使不等式左边尽量大即可。现在不 阅读全文
posted @ 2011-03-23 21:37 undefined2024 阅读(1614) 评论(0) 推荐(0)
摘要: 按c排序,c相同则按d排序(均从小到大),从左至右遍历,当发现一个的d比前面出现过的最小的d还小那么它一定是解。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 10005struct Hotel{ int c, d;} f[maxn];int n, ans;bool operator <(const Hotel 阅读全文
posted @ 2011-03-23 20:46 undefined2024 阅读(221) 评论(0) 推荐(0)
摘要: 思想是将位于起始点和结束点之间的所有房子之间的空隙进行扩展。将房子按高度排序,记录排序后每个房子的起始位置。用span[i]记录第i次跳跃的长度。我枚举起始点和结束点之间的每一个空隙,看跳跃过程中所有需要经过这个空隙的所有跳跃中跨度最大的是多少,记录在maxdist中,则经过思考发现,刚才所有跨越此空隙可增加d-maxdist,增加后需要更新span数组。把所有空隙用上述方法扩大后得到答案。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring& 阅读全文
posted @ 2011-03-23 20:36 undefined2024 阅读(154) 评论(0) 推荐(0)
上一页 1 ··· 160 161 162 163 164 165 166 167 168 ··· 182 下一页