标签:des style blog http color io os ar java
坑爹啊!弄了半个小时,数组越界啊!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10719 Accepted Submission(s): 3746
1 # include<iostream> 2 # include<cstdio> 3 # include<string.h> 4 # include<algorithm> 5 using namespace std; 6 int cmp(const int a,const int b) 7 { 8 return a>b; 9 } 10 int a[3005],hash[3000*3000/2]; 11 int main() 12 { 13 14 int n,m; 15 while(cin>>n>>m) 16 { 17 for(int i = 0;i < n;i++) 18 { 19 cin>>a[i]; 20 } 21 int k = 0; 22 for(int j = 0;j < n -1;j++) 23 { 24 for(int v = j+1;v < n;v++) 25 { 26 hash[k++] = a[j]+a[v]; 27 } 28 } 29 sort(hash,hash+(n*(n-1))/2,cmp); 30 for(int i = 0;i < m;i++) 31 { 32 if(!i) 33 cout<<hash[i]; 34 else 35 cout<<" "<<hash[i]; 36 } 37 cout<<endl; 38 } 39 }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/sxmcACM/p/4004371.html