上一页 1 ··· 5 6 7 8 9

2012年7月1日

用STL实现优先队列

摘要: #include<iostream>#include<queue>using namespace std;struct node{ int a; int b; };struct cmp{ //reset operator for node bool operator ()(const node &c,const node &d){ return (c.a<d.a); //from high to low } };int main(){ int c[5]={3,1,12,6,5}; node b[5]; b[0].a=2; b[1].a=5; b[3 阅读全文

posted @ 2012-07-01 11:28 yumao 阅读(275) 评论(0) 推荐(0) 编辑

2012年6月28日

最小生成树问题

摘要: hdu 1233还是畅通工程Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13138 Accepted Submission(s): 6016Problem Description某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。Input测试输入包含若干 阅读全文

posted @ 2012-06-28 23:05 yumao 阅读(135) 评论(0) 推荐(0) 编辑

2012年6月27日

并查集问题

摘要: hdu 1213畅通工程Problem Description某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( < 1000 )和道路数目M;随后的M行对应M条道路,每行给出一对正整数,分别是该条道路直接连通的两个城镇的编号。为简单起见,城镇从1到N编号。 注意:两个城市之间可以有多条道路相通,也就是说3 31 21 2 阅读全文

posted @ 2012-06-27 11:36 yumao 阅读(192) 评论(1) 推荐(0) 编辑

2012年6月21日

gets() scanf("%s") puts() printf("%s") 的区别

摘要: gets()与scanf(“%s”): ① gets遇回车时结束输入。也就是说,gets可以接受回车前的任何输入。 scanf不同,遇到回车、空格、制表符就结束输入。 eg. String a=”I am a student; 如果要一次性的接受全部的字符串,要用gets。 ② 输入结束后,gets的回车不会留在缓冲区;而scanf的空格、回车仍然会留在缓冲区。Puts()与printf(“%s”): ① puts函数只用来输出字符串,参数可以是字符串,也可以是存放字符串的数组名。 Printf(“%s”)其参数也可以是是字符串,或者是存放字符串的数组名。 ② puts函数输出字符串后会自动加 阅读全文

posted @ 2012-06-21 11:31 yumao 阅读(785) 评论(0) 推荐(0) 编辑

2012年6月19日

codeforces 1A

摘要: A. Theatre Squaretime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputTheatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the 阅读全文

posted @ 2012-06-19 23:38 yumao 阅读(232) 评论(1) 推荐(0) 编辑

水题时的一些问题

摘要: 1. 为什么 int sum=pow(k,2)+k+41; cout<<pow(k,2)+k+41<<endl; cout<<sum<<endl; 输出不一样? (double-int的转换)2. 为什么在比较简单的题目中,用char a[100];scanf("%s",a)会超时?用gets()则不会。eg. hdu 2000 , hdu 2005 阅读全文

posted @ 2012-06-19 11:07 yumao 阅读(122) 评论(2) 推荐(0) 编辑

水题时,一些零碎的总结

摘要: 1. 用printf(“%.nf”,….);输出精确n位的小数,结果会自动四舍五入。2. double->int 时,不论double中的小数为什么,int 型都只取double中的整数。3. 求绝对值时: abs()为int型 fabs()为双精度浮点型 cabs()为复数的 labs()为long int型4. 开平方为: sqrt()5. pow()函数返回的为double型,对于结果的转换要注意,容易被强制转换成int,然后就有可能出现问题。6. 用库函数: #include<algorithm> int a[10]; sort(a,a+10);7. 用‘/’时,如果 阅读全文

posted @ 2012-06-19 10:50 yumao 阅读(138) 评论(0) 推荐(0) 编辑

上一页 1 ··· 5 6 7 8 9

导航