稳定婚姻匹配可参考Matrix67的博客http://www.matrix67.com/blog另外可参考Richard A.Brualdi的《组合数学》 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn=200; 7 int T,n,wp[maxn][maxn],wm[maxn],mm[maxn]; 8 9 int tran(char s)10 {11 int d=s;12 return d;13 }14 int main()15 {16 //fre... Read More
posted @ 2013-07-10 14:45 longlongago Views(486) Comments(0) Diggs(0) Edit
每修好一台电脑后就逐一与之前修好的电脑进行距离计算,若距离小于等于d则加入同一集合。写的时候各种不认真,wa了好几次,应该好好批评下自己。 1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 #include<math.h> 5 const int maxn=1010; 6 int p[maxn],n,d,repair[maxn],k; 7 struct Node 8 { 9 double x,y;10 bool flag;11 }node[maxn];12 13 void Read More
posted @ 2013-06-12 01:23 longlongago Views(176) Comments(0) Diggs(0) Edit
poj1182是此题的加强版。若两人属于不同集合则他们所属帮派未知。若属于同一集合,设ra=find(a),若rank[a]==0,则a与ra为同一帮派,反之rank[a]==1,a与ra则分属于不同帮派。另外测下这组数据 1 2 1 A 1 2 答案应该是In different gangs.(在discuss里看到的)。 1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 using namespace std; 5 const int maxn=100001; 6 int p[m Read More
posted @ 2013-06-10 19:43 longlongago Views(110) Comments(0) Diggs(0) Edit
并查集的基础题。在加入边前检查两点之前是否是同一个集合,若是则不是一棵树。输入完后检查是否所有点属于同一个集合。 1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 using namespace std; 5 const int maxn=1<<15; 6 bool flag,vis[maxn]; 7 int p[maxn],rank[maxn],data[maxn],m; 8 int a,b,ra,rb; 9 10 int find(int x)11 {12 if(x! Read More
posted @ 2013-06-10 18:38 longlongago Views(99) Comments(0) Diggs(0) Edit
并查集的基础题。总共n个人,有m组人有相同信仰。问这些人中存在的信仰最多有多少种。 1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 using namespace std; 5 const int maxn=50001; 6 int p[maxn],rank[maxn]; 7 bool vis[maxn]; 8 9 int find(int v)10 {11 if(p[v]==v)12 return v;13 else14 {15 p[v]=find(p[v]);16... Read More
posted @ 2013-06-03 11:47 longlongago Views(113) Comments(0) Diggs(0) Edit
这题wa了好久,然后再discuss里看了一下,查询的字符串居然可以重复出现,也就是说12aaa应该是2不是1。。。。 感觉再也不会爱了== 1 #include<iostream> 2 #include<cstdio> 3 #include<string.h> 4 #include<queue> 5 using namespace std; 6 const int maxn=10001; 7 char tree[51],p[maxn*100]; 8 int cnt,val[maxn*50],f[maxn*50],last[maxn*50]; 9 Read More
posted @ 2013-05-26 15:31 longlongago Views(145) Comments(0) Diggs(0) Edit
AC自动机的裸题。虽然是水题却做了很久,居然在每次查询的脑残的去修改字典树的信息。还有数组开小了居然会返回wa。。。 1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<queue> 5 #include<algorithm> 6 using namespace std; 7 const int maxn=85010; 8 const int sig=100; 9 int ch[maxn][sig],last[maxn],f[maxn],nu Read More
posted @ 2013-05-26 00:18 longlongago Views(126) Comments(0) Diggs(0) Edit
一开始做这道题没什么头绪,那时只会写Trie,ac自动机不怎么懂。后来在discuss里看到要用AC自动机做。先把要查询的字符串添加进Trie图里,建完自动机后再从矩形四周八个方向依次查询,结果放在数组里。 1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 #include<queue> 5 using namespace std; 6 const int maxn=1001; 7 char g[maxn][maxn],T[maxn][maxn],str[maxn]; 8 Read More
posted @ 2013-05-22 20:55 longlongago Views(123) Comments(0) Diggs(0) Edit
状态方程为dp[i][s]=dp[i-1][s']+dp[i-1][s] (sum[s]<i)或dp[i][s]=dp[i-1][s'] (sum[s]==i)如果s与base矛盾,则s'必须含有s与base矛盾的项。(其中i为第几行,s为状态,s'为是的子状态,base数组记录棋盘状态('.'为1,'#'为0),sum[s]记录s中1的个数)View Code #include<iostream>#include<cstdio>#include<string.h>using namesp Read More
posted @ 2013-04-25 22:15 longlongago Views(173) Comments(0) Diggs(0) Edit
具体做法可参照Matrix67大牛的博客http://www.matrix67.com/blog/archives/266View Code #include<cstdio>#include<string.h>#include<iostream>using namespace std;int up,n,k,sum;void test(int row,int ld,int rd,int cnt,int now){ if(now>n) return; if(cnt<k) { int pos=up&(~(ld|rd|row)); int p; Read More
posted @ 2013-04-25 00:08 longlongago Views(131) Comments(0) Diggs(0) Edit