上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 57 下一页

2011年7月20日

poj 1182 食物链

摘要: #include <iostream> using namespace std;int n,k,d,x,y,par[50010],rel[50010];void init(){ for(int i=1;i<=n;++i) { par[i]=i; } memset(rel,0,sizeof(rel));}int Find(int x){ int temp_p; if (par[x] != x) { // 因为路径压缩,该结点的与根结点的关系要更新(因为前面合并时可能还没来得及更新). temp_p = par[x]; par[x] = Find(par[x]); // x与根结 阅读全文

posted @ 2011-07-20 22:35 sysu_mjc 阅读(126) 评论(0) 推荐(0) 编辑

poj 1126 Simply Syntax

摘要: #include <iostream>#include <string>using namespace std;int main(){ string data; int i,top,list[260]; bool tag; while(cin>>data) { top=data.size()-1; tag=1; for(i=0;i<=top;i++) { if(data[i]=='N') list[i]=1; else if(data[i]=='C'||data[i]=='D'||data[i]== 阅读全文

posted @ 2011-07-20 22:34 sysu_mjc 阅读(136) 评论(0) 推荐(0) 编辑

poj 1088 滑雪

摘要: #include <iostream>using namespace std;int r,c,height[101][101],skate[101][101];int dp(int i,int j){ int up,down,left,right,max=0; if(i>1&&height[i][j]>height[i-1][j]) { if(skate[i-1][j]!=0) down=skate[i-1][j]; else down=dp(i-1,j); if(max<down)max=down; } if(i<r&&he 阅读全文

posted @ 2011-07-20 22:33 sysu_mjc 阅读(108) 评论(0) 推荐(0) 编辑

poj 1080 Human Gene Functions

摘要: #include <iostream> //DPusing namespace std;int max(int a,int b,int c){ int aa=a,bb=b,cc=c; if(aa<bb)swap(aa,bb); return aa>cc?aa:cc;}int matrix(char a,char b){ if(a=='A') { switch (b) { case 'A':return 5;break; case 'C':return -1;break; case 'G':return -2 阅读全文

posted @ 2011-07-20 22:32 sysu_mjc 阅读(132) 评论(0) 推荐(0) 编辑

poj 1020 Anniversary Cake

摘要: #include <iostream>using namespace std;int cnt[20], len[50];int cake_side, npiece;bool dfs(int used) //从上往下放,每次放在被覆盖最少的列上。{ if(used == npiece) return true; int min = 100, ind; for(int i = 0; i < cake_side; i++) //i=0表示第一列 { if(len[i]<min) { min = len[i]; ind = i; } } for(int i = 1; i < 阅读全文

posted @ 2011-07-20 22:31 sysu_mjc 阅读(192) 评论(0) 推荐(0) 编辑

poj 1014 Dividing

摘要: #include <iostream>using namespace std;int num[7],total;bool flag;bool find(int sum) { if(sum==total) { flag=1; return true; } else if(sum>total) return false; else { int s; for(int i=6;i>=1;i--) //这里相当于下面程序的pre { if(num[i]==0||i>total) continue; s=sum+i; num[i]--; if(find(s)) return 阅读全文

posted @ 2011-07-20 22:30 sysu_mjc 阅读(158) 评论(0) 推荐(0) 编辑

poj 1013 Counterfeit Dollar

摘要: #include <iostream>#include <map>#include <string>using namespace std;string str1[3],str2[3],com[3];/*若没有is_counterfeit()函数,则下面测试数据的输出结果是 G,但正确应该是 I ABCDEF GHIJKL up ABC DEF even I J down */bool is_counterfeit(char a) { for(int i=0;i<3;i++) { if(com[i]=="even") continu 阅读全文

posted @ 2011-07-20 22:29 sysu_mjc 阅读(113) 评论(0) 推荐(0) 编辑

poj 1012 Joseph

摘要: #include <iostream> //约瑟夫环using namespace std;int res[14];bool Joseph(int k,int m){ int len=2*k,i=0; while(len>k) { i=(i+m-1)%len; //i是被踢出的数的下标 if(i<k)return 0; //因为前k个都不能先选出来,所以前k个数的下标一直未变,只要i<k说明前k个数之一被踢出//这样就不用把选中的数从数组中删除,并把每次删除的数与k进行比较,现在直接把坐标与k进行比较即可 len--; } return 1;}int main() 阅读全文

posted @ 2011-07-20 22:28 sysu_mjc 阅读(107) 评论(0) 推荐(0) 编辑

poj 1008 Maya Calendar

摘要: #include <iostream>#include <string>using namespace std;char Haab_months[19][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac 阅读全文

posted @ 2011-07-20 22:27 sysu_mjc 阅读(119) 评论(0) 推荐(0) 编辑

2011年7月19日

二分图匹配----匈牙利算法之六

摘要: poj 2226 Muddy Fields/*题意 :有R×C方阵,'*'表示洼地,需要铺上宽度为1的木板,长度不限,只能横放或竖放.木板可以重叠,但不能覆盖'.'求覆盖所有'*'洼地所用的最少木板数.构图: 将所有横向且连续(一个或以上)的'*'看成一个点并对其进行编号,所有的编号都为集合X内的编号。同样地,将所有的竖向且连续(一个或以上)的'*'看成一个点并对其编号,所有的编号都为集合Y内的编号对于原图里的'*',设其在横向X编号为i,在竖向Y编号为j,则在点 Xi 和点 Yj 间连一 阅读全文

posted @ 2011-07-19 21:39 sysu_mjc 阅读(162) 评论(0) 推荐(0) 编辑

上一页 1 ··· 32 33 34 35 36 37 38 39 40 ··· 57 下一页

导航