摘要: 博弈,找规律题意:摆一圈硬币,两人轮流取,每次取一个或者位置相邻的两个(最开始就要相邻,因为中间硬币被取走而相邻的不算)。谁无币可取谁输。问谁赢。分析:对于许多硬币的情况,先手必然把这堆硬币由一个环拆开一个缺口变为了一条线,后手的任务是将一条线拆成一样长得两条线(必定能实现),然后跟着先手在两条线之间做对称的动作即可。View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>usingnamespace std;int main(){ //f 阅读全文
posted @ 2011-09-06 20:31 undefined2024 阅读(290) 评论(0) 推荐(0)
摘要: 题意:平面上有许多点,每个点有一个权值。给定一个大小确定的矩形,边与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 阅读(174) 评论(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 阅读(463) 评论(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)
摘要: 求欧拉回路。对全图进行dfs,从规定起点开始。过程中记录经过了哪些边,以保证每条边只经过一次。当一个点的所有边都遍历完成后,把该点入栈。最后依次弹栈得到的就是欧拉路径。被入栈的点都是走投无路的点,如果存在欧拉路径,第一次出现的走投无路一定是在走回到起点时,因为其他情况无论怎么走只可能略过一些边,而不可能走进死路。本题要把每条边加为双向边。View Code #include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;#def 阅读全文
posted @ 2011-09-06 08:36 undefined2024 阅读(452) 评论(0) 推荐(0)