标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4504 Accepted Submission(s): 1838
#include<stdio.h> #include<string.h> #include<queue> #include<algorithm> using namespace std; bool cmp(int a,int b) { return a>b; } int str[100010]; int main() { int n,m,j,i,s,t; while(scanf("%d%d",&n,&m)&&n!=0&&m!=0) { for(i=0;i<n;i++) { scanf("%d",&str[i]); } sort(str,str+n,cmp); if(n>m) { for(i=0;i<m;i++) { if(i==0) printf("%d",str[i]); else printf(" %d",str[i]); } printf("\n"); } else { for(i=0;i<n;i++) { if(i==0) printf("%d",str[i]); else printf(" %d",str[i]); } printf("\n"); } } return 0; }
优先队列:
#include<stdio.h> #include<queue> using namespace std; int main() { int n,m,j,i,t,k; while(scanf("%d%d",&n,&m)&&n!=0&&m!=0) { priority_queue<int>q; int c=n; while(c--) { scanf("%d",&t); q.push(t); } if(n<m) { k=n;n=m;m=k; } int a=n-m; int p=0; while(q.size()>a) { if(p==0) printf("%d",q.top()); else printf(" %d",q.top()); p++; q.pop(); } printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4683474.html