摘要: 并查集,欧拉回路View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 int n,len1; 5 char s[1005]; 6 int a[30],b[30]; 7 int set[30]; 8 int find(int x) 9 {10 if(x!=set[x])11 set[x]=find(set[x]);12 return set[x];13 }14 void met()15 {16 int i,x,y;17 for(i=1;i<=n;i++)... 阅读全文
posted @ 2012-08-01 17:13 zlyblog 阅读(194) 评论(0) 推荐(0)
摘要: 这个题主要有个小细节就是n=0时,应该输出1;这里给出两种方法:View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define N 10000005 5 int set[N],b[100005]; 6 int a[100005]; 7 int s[100005]; 8 int find(int x) 9 {10 if(x==set[x])11 return x;12 else13 set[x]=find(set[x]);14 }15 int ma... 阅读全文
posted @ 2012-08-01 15:16 zlyblog 阅读(200) 评论(0) 推荐(0)
摘要: 跟小希的迷宫有些相似。但却不知道为什么那些做法放这里就超时了。……View Code 1 2 #include <iostream> 3 #include <string.h> 4 #include <string> 5 #include <cstdio> 6 using namespace std; 7 int leftt[10005],rightt[10005],father[10005]; 8 int find(int x){ 9 if(father[x]==-1)10 return x;11 return find(father[x]); 阅读全文
posted @ 2012-08-01 10:58 zlyblog 阅读(205) 评论(0) 推荐(0)