#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm> #include<stack> #include<queue> #include<cctype> #include<sstream> using namespace std; #define pii pair<int,int> #define LL long long int const double eps=1e-10; const int INF=1000000000; const int maxn=750+10; int n,a[maxn][maxn]; struct node { int s,b; node(int s,int b): s(s),b(b){} bool operator < (const node &x) const { return s>x.s; } }; priority_queue<node>pq; void he(int *A,int *B,int *C) { while(!pq.empty()) pq.pop(); for(int i=0; i<n; i++) { pq.push(node(A[i]+B[0],0)); } for(int i=0; i<n; i++) { node t=pq.top(); pq.pop(); C[i]=t.s; pq.push(node(t.s-B[t.b]+B[t.b+1],t.b+1)); } } int main() { //freopen("in1.txt","r",stdin); //freopen("out.txt","w",stdout); while(scanf("%d",&n)==1) { for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { scanf("%d",&a[i][j]); } sort(a[i],a[i]+n); } for(int i=1; i<n; i++) { he(a[0],a[i],a[0]); } for(int i=0; i<n-1; i++) printf("%d ",a[0][i]); printf("%d\n",a[0][n-1]); } return 0; }
相关文章: