hdu1106 排序 堆排序
来源:互联网 发布:打印机无法网络打印 编辑:程序博客网 时间:2024/06/05 21:12
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#define N 2000using namespace std;__int64 heap[N];char str[2000];char str1[1010];char Map[1010][1100];int print_in(__int64 a){ if(heap[0]==N) return -1; heap[++heap[0]]=a; int x=heap[0]; int p=x/2; while(p>0&&heap[p]>heap[x]) { swap(heap[p],heap[x]); x=p; p=p/2; } return 0;}int print_out(){ if(heap[0]==0) return -1; __int64 ret=heap[1]; swap(heap[1],heap[heap[0]]); heap[0]--; int p=1,x; int lc,rc; while(1) { lc=p<<1; rc=p<<1|1; x=p; if(lc<=heap[0]&&heap[lc]<heap[x]) x=lc; if(rc<=heap[0]&&heap[rc]<heap[x]) x=rc; if(x==p) break; swap(heap[x],heap[p]); p=x; } return ret;}int main(){ __int64 a; while(~scanf("%s",str)) { heap[0]=0; int j=0,k=0; int len=strlen(str); for(int i=0; i<len; i++) { if(str[i]=='5') { if(j!=0) { str1[j]='\0'; strcpy(Map[k++],str1); j=0; } } else if(str[i]!='5') { str1[j++]=str[i]; } } if(str[len-1]!='5') { str1[j]='\0'; strcpy(Map[k++],str1); } for(int i=0; i<k; i++) { a=0; for(int j=0; j<strlen(Map[i]); j++) { a=a*10+Map[i][j]-'0'; } print_in(a); } while(heap[0]>0) { cout<<print_out(); putchar(heap[0]!=0?' ':'\n'); } } return 0;}
0 0
- hdu1106 排序 堆排序
- hdu1106 排序(堆排序)
- HDU1106:排序
- hdu1106 排序
- hdu1106( 排序)
- HDU1106--排序
- hdu1106排序
- hdu1106排序
- hdu1106排序
- hdu1106-排序
- HDU1106 排序
- hdu1106排序
- HDU1106 排序
- HDU1106 排序
- HDU1106排序
- HDU1106 排序
- HDU1106-排序
- HDU1106 排序
- java设计模式-代理模式小结
- 多方位解析PHP vs Node.js之争
- BZOJ 3316 JC loves Mkk 二分答案+单调队列
- 连接数据库错误The Network Adapter could not establish the connection
- [leetcode] Pascal's Triangle II
- hdu1106 排序 堆排序
- StateMachine与State模式
- Codeforces Round #285 (Div. 2) D. Misha and Permutations Summation 康托展开 树状数组+二分
- Dispatcher initialization failed怎么解决
- HashSet和HashMap的区别
- iOS裁剪图片
- 2012年11月6日 不存在
- 【学QT】 3 - DEBUG集子
- cut命令