摘要: /*不能算是并查集,只是用了路径压缩和树的特点,和1272的区别在于它是有向图,它的父结点是固定的*/#include <iostream>using namespace std;int main(){ int n,m,k=0,s[100005]={0},j=0,i,big; bool f=0; bool flag[100005]={0}; while(cin>>n>>m) { if(m==-1&&n==-1)return 0; if(m==0&&n==0) { k++; int... 阅读全文
posted @ 2012-01-18 19:24 windmissing 阅读(101) 评论(0) 推荐(0) 编辑
摘要: /*并查集的应用,注意点的个数为0的时候,注意输入*/#include <iostream>#include "UFS.h"using namespace std;UFS ufs;bool flag[MAXN]={0}, f;int cnt_e, cnt_v;void init();int main(){ int n,m; init(); while(cin>>n>>m) { if(m==-1&&n==-1)return 0; if(m==0&&n==0) { getchar();getchar(); /* 阅读全文
posted @ 2012-01-18 18:04 windmissing 阅读(93) 评论(0) 推荐(0) 编辑
摘要: /*HDU1829A Bug's Life 并查集的应用这题不是判断是否在同一集合,而是判断是否在不同的集合*/#include <iostream>#include "UFS.h"using namespace std;int oppo[MAXN];//记录系第一个BUG的异性所在的集合的编号int main(){ int t; int n,m,i,j; UFS ufs; scanf("%d",&t); for(j=1;j<=t;j++) { bool f=0; memset(oppo, 0, sizeof(oppo) 阅读全文
posted @ 2012-01-18 15:49 windmissing 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 1.在一个类中定义了一个新的类型,这个类型只能在该类用使用。新类型称为嵌套类2.endl在执行时,做两件事情:1)输入'\n'2)刷新缓冲区flush()解释:执行换行符\n与执行结束符endl,最大的区别在处理文件上,以文件输出流(ofstream)为例。当流的缓冲区未满时,执行'\n'是不会马上写到文件里。但是执行endl会强行把缓冲区里的内容写入文件中。3.输出数据到文件的步骤:1)包含头文件stream2)建立ofstream对象:ofstream ocout;3)将对象与文件关联:ocout.open("123.txt");4)使用 阅读全文
posted @ 2012-01-18 15:02 windmissing 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 1.字符数组、字符串与string类的区别例1:int main(){ string s; cin>>s;//输入:dog if(s == "dog") cout<<"狗"<<endl; char ch[10]; cin>>ch;//输入:cat if(ch == "cat") cout<<"猫"<<endl; return 0;}输出:dog //输入狗 //输出cat//输入解释:数组名是该数组第一个元素的内存地址用引号括起来的字符串也代表 阅读全文
posted @ 2012-01-18 14:44 windmissing 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 1.一个函数的指针,必须确保该函数被定义且分配了内存,否则将指向空地址,这是指针的大忌。2.函数指针的使用条件:参数、返回值都吻合‘3.函数指针没有++或--的运算4.函数指针作为参数的最好的例子就是回调函数5.函数指针的使用例:void (*p)(int &, int &);void cube(int &x, int &y){ x = x * x * x; y = y * y * y;}void Test(void (*p)(int &, int &), int &a, int &b){ p(a, b); cout<< 阅读全文
posted @ 2012-01-18 14:25 windmissing 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 1. 传递数组的3种方式1)void func(int a[]);2)void func(int a[5]);3)void func(int *a);例:void func1(int a[], int n);void func2(int a[5], int n);void func3(int *a, int n);int main(){ int a[10], i; for(i = 0; i < 10; i++) a[i] = i + 1; func1(a, 10); func2(a, 10); func3(a, 10); return 0;}void func1(int a[], int 阅读全文
posted @ 2012-01-18 09:54 windmissing 阅读(139) 评论(0) 推荐(0) 编辑