ITeye博客

ITfreshman的博客

ITfreshman · 共 3 篇文章

C++经典排序

/*本程序综合了几乎所有的排序方法。其中: getdata(sample &s):用于获取对象s的数据 insertsort(sample &s):用于进行插入排序 shellsort(sample &s):用于进行希尔排序 bubblesort(sample &s):用于进行冒泡排序 quicksort(sample &s):用于进行快速排序 selectsort(sample &s):用于进行选择排序 disp(sample &s):用于数据输出 最后说明的是:这儿顺便展示了友元的用法 */ #include <iostream.h> #define max 100 class samp…

2012-02-14 14:17 · 排序 · 评论(0)

POJ1860

最初,一直在纠结后面大循环需要用2*n还是n+1次,考虑了只有某一个point具有显著盈利的exchange ratio时,最远返回到起始currency s的最坏情况。但后来看了别人的解答,才想到了,可能存在一个小的回路,exchange ratio盈利但是并不显著,那么这个需要的次数可能为正无穷,所以就要从是否有currency在某回路反复是否有增加的情况考虑。 后来WA了很多次,最后就只是把float改成double就过了。还没想通原因。。。题目中要求10-2<=rate<=102 #include<iostream> #define MAXn 100 double quantity[…

2012-02-08 10:49 · 最短路径算法 · 评论(0)

POJ2777

一开始总是TLE。。。偶然看到discuss里面有人说用cin就会TLE。然后我用 char cp; scanf("%c",&cp); 不知道为什么while(O--)的次数有问题了,再没有输入'C'或'P'时也会有循环。后来仿照网上的解法,用 char cp[10]; scanf("%s", cp); 具体原因有待研究。。。 还有一个疑惑就是为什么要开4倍大小的空间? #include <iostream> using namespace std; #define maxn 100010 struct node { int l,r; int c; int lazy; }T[maxn*4];…

2012-02-05 17:59 · 线段树 · 评论(0)