摘要:
简单并查集View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;#define maxn 1005#define eps 1.0e-8struct Computer{ int x, y; bool r;}computer[maxn];int n, d;int father[maxn];int getanc(int a){ if (father[a] == 阅读全文
posted @ 2011-05-27 13:20
undefined2024
阅读(305)
评论(0)
推荐(0)
摘要:
题意:有n堆石子,每人每次可以从一堆中拿走任意多个,两人轮流操作,谁无子可取谁输。输入n堆石子各自的数量,输出先手是否能赢。分析:NP问题,必胜态N(next player wins),必败态P(previous player wins)如果某状态的直接后继中有必败态那么它一定是必胜态,否则为必败态。SG函数。设函数g(x)。我们先把所有的最终局面(最终局面均为必败P局面)g(x)赋值为0。然后所有其他局面g(x)等于其直接后继状态中没有出现过的最小自然数。这样一来所有是g(x)=0的状态就是必败态,其他为必胜态。根据定理:有这样一个游戏,是多个游戏共同进行,每个游戏都执行到底时才算整个游戏结 阅读全文
posted @ 2011-05-27 12:52
undefined2024
阅读(1125)
评论(0)
推荐(0)
摘要:
简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define maxn 10006int f[maxn];int main(){ //freopen("t.txt", "r", stdin); int n; scanf("%d", &n); for (int i = 阅读全文
posted @ 2011-05-27 12:23
undefined2024
阅读(124)
评论(0)
推荐(0)
摘要:
题意:把n拆分为2的幂相加的形式,问有多少种拆分方法。分析:dp,任何dp一定要注意各个状态来源不能有重复情况。根据奇偶分两种情况,如果n是奇数则与n-1的情况相同。如果n是偶数则还可以分为两种情况,有1和没有1。这样分可以保证两种情况没有重复,对于有1的情况可以直接拆出两个1(拆一个也行,但变成奇数之后一定会拆另一个),然后变为n-2的情况。对于没有1的情况可以直接将其转化为n/2。因为n拆分出所有的数字都是2的倍数。只需要将每种拆分结果中的数字都除以2就会与n/2的一种拆分相对应。View Code #include #include #include #include usingname 阅读全文
posted @ 2011-05-27 11:26
undefined2024
阅读(1275)
评论(0)
推荐(0)
摘要:
题意比较难理解,第二个数字是指数,从数列中选择任意多个,使得他们每个求幂再求和最大。View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>using namespace std;int main(){ //freopen("t.txt", "r", stdin); int n, p; scanf("%d%d", &n, & 阅读全文
posted @ 2011-05-27 11:02
undefined2024
阅读(331)
评论(0)
推荐(0)