Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
蛋疼,2442老WA,谁能帮我看看代码: /*pku2442*/ #include <iostream> #include <algorithm> #include <cstring> using namespace std; long long data[2010],sum[20010],temp[2010]; void fun(int n,int i){ for(int j=n-1;j>i;j--) sum[j]=sum[j-1]; } void insert(long long a,int n){ for(int i=n-1;i>0;i--){ if(sum[i-1]<=a){ fun(n,i); sum[i]=a; return; } } if(sum[0]>a){ fun(n,0); sum[0]=a; } } int main(){ int m,n,t,i,j; cin>>t; while(t--){ cin>>m>>n; long long pos=0; memset(data,0,sizeof(data)); memset(temp,0,sizeof(temp)); memset(sum,0,sizeof(sum)); for(i=0;i<m;i++){ pos=0; if(i==0){ for(j=0;j<n;j++){ cin>>data[j]; } sort(data,data+n); continue; } for(j=0;j<n;j++){ cin>>temp[j]; } sort(temp,temp+n); for(j=0;j<n;j++){ for(int l=0;l<n;l++){ sum[pos++]=data[l]+temp[j]; if(pos<n) continue; if(data[l]+temp[j]>=sum[n-1]) break; insert(sum[pos-1],n); } pos=n; if(data[0]+temp[j+1]>=sum[n-1]) break; } sort(sum,sum+n); for(j=0;j<n;j++){ data[j]=sum[j]; } } for(i=0;i<n-1;i++) cout<<sum[i]<<' '; cout<<sum[i]<<endl; } system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator