摘要:
题意:平面上有许多点,每个点有一个权值。给定一个大小确定的矩形,边与x,y轴平行,平移这个矩形能圈住的点的权值之和最大是多少。分析:线段树 c++ac g++re先把题目转化一下,用矩形的中心点来描述这个矩形的位置。并对每个点建立一个矩形中心点的活动范围,即矩形中心点在这个范围内即可覆盖到该点,建立方法就是以每个点为中心画一个与题中矩形大小相等的矩形。现在点变成了矩形,矩形变成了点。我们要求的是找一个位置来放这个点使得它在最多的矩形内部,即该点的矩形重叠层数最多。这样我们就可以用线段树来解决了,用一条与y轴平行的扫描线,从左到右来扫描这个矩形重叠图。这条扫描线就是线段树中的整条线段区间,在一个 阅读全文
posted @ 2011-09-06 18:56
undefined2024
阅读(2692)
评论(0)
推荐(1)
摘要:
位操作枚举View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 1005int n, d, k;int cow[maxn];bool ok(int a){ int ret = 0; while (a) { ret += (a & 1); a >>= 1; } return ret == k;}int main(){ //freopen("t.t 阅读全文
posted @ 2011-09-06 14:15
undefined2024
阅读(175)
评论(0)
推荐(0)
摘要:
最短路,有重边View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#define N 505int path[N], vis[N];int n, m, c, p;int lowcost[N];int cost[N][N];int cow[N];int ans[N];void Dijkstra(){ in 阅读全文
posted @ 2011-09-06 13:58
undefined2024
阅读(198)
评论(0)
推荐(0)
摘要:
动态规划View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#define maxn 1005#define maxw 35int n, w;int apple[maxn][2];int f[maxw][maxn][2];int main(){ //freopen("t.txt", "r", stdin); scanf("%d%d", & 阅读全文
posted @ 2011-09-06 13:21
undefined2024
阅读(464)
评论(0)
推荐(0)
摘要:
排序+贪心View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;#define maxn 25005struct Interval{ int s, e;}interval[maxn];int n, t;bool operator < (const Interval &a, const Interval &b){ if (a.s 阅读全文
posted @ 2011-09-06 09:38
undefined2024
阅读(457)
评论(0)
推荐(0)