标签:des style blog http color os io java ar
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10633 Accepted Submission(s): 3707
public static void Sort(int[] A, out int[] B, int k) { Debug.Assert(k > 0); Debug.Assert(A != null); int[] C = new int[k + 1]; B = new int[A.Length]; for (int j = 0; j < A.Length; j++) { C[A[j]]++; } for (int i = 1; i <= k; i++) { C[i] += C[i-1]; } for (int j = A.Length - 1; j >= 0; j--) { B[C[A[j]]-1] = A[j]; C[A[j]]--; } }
#include<stdio.h> #include<string.h> #include<stdlib.h> int main(){ int n,m,i,j,mac; //system("call test.in"); //freopen("test.in","r",stdin); while(scanf("%d%d",&n,&m)!=EOF){ int * aa= (int *)malloc(sizeof(int)*n); for(mac=i=0;i<n;i++){ scanf("%d",aa+i); if(mac<aa[i])mac=aa[i]; } int *cc =(int *)malloc(sizeof(int)*(mac*2+1)); for(i=0;i<=mac*2;i++)cc[i]=0; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) cc[aa[i]+aa[j]]++; free(aa); for(i=mac*2;i>=0;i--){ while(cc[i]){ if(m==1) printf("%d\n",i); else printf("%d ",i); cc[i]--; m--; if(m==0)goto loop; } } loop: free(cc); } return 0; }
标签:des style blog http color os io java ar
原文地址:http://www.cnblogs.com/gongxijun/p/3961136.html