ACM普通题
文章平均质量分 68
yzzy101010
这个作者很懒,什么都没留下…
展开
-
hdu1232
典型的并查集类型,将联通的点归为一个集合,最后一共有count个集合。则需要修建count-1条道路。 #include using namespace std; int set[1001];//全局变量模拟n个点 int find(int x)//查找原始祖先 { int r=x; while(set[r]!=r) r=set[r]; return r; }原创 2011-12-20 22:01:08 · 164 阅读 · 0 评论 -
poj2299
排序后求交换次数,其实就是求逆序数。由于数据庞大,冒泡解决时间复杂度为O(n*n)会超时。所以用归并排序的方法时间复杂度降为O(n*logn)。 主要难点在于归并排序如何求逆序数, 在每次对2个有序集合进行merge时,当右边集合的elem[j]小于左边集合elem[i]时,则说明elem[j]小于左边集合 elem[i]---elem[mid] mid-i+1个元素的值。则对于这个元素,原创 2011-12-20 11:00:55 · 163 阅读 · 0 评论 -
hdu1050
Moving Tables 模拟题,用数组模拟房间前的过道是被占用的次数。每次输入就将2个房之间所有的房间过道占用次数加一,其实就是计算房间 重叠最多的次数为多少。 #include using namespace std; int main() { int T,mark[402],j=0; cin>>T; while(j++!=T)原创 2011-12-19 21:31:19 · 225 阅读 · 0 评论 -
hdu1028
母函数问题,用多项式相乘的系数来模拟整数的分解。G(x)=(1+x+...)(1+x^2+...)(1+x^3....)...(1+x^n) #include using namespace std; int main() { int n,i,j,k,a[130],b[130]; while(cin>>n&&n!=-1) {原创 2011-12-19 21:24:58 · 182 阅读 · 0 评论 -
处理字符串的四则运算(2013小米笔试题)
输入: 2+3*(4-5) 1+1 输出: -1.0 2.0 类似于四则运算的实现(+ - * / ^) 数据结构: Stack opr 字符栈 Stack num 数字栈 HashMap map 优先级 算法: 1.先用map给运算符定义优先级 [ +=1 , -=1 , *=2 , /=2 , ^=3 , (=10 , )=0 ] 2.从左到右依次录入字原创 2013-10-18 22:37:58 · 402 阅读 · 0 评论