标签:sum span include top sort int max names pop
多路归并
#include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> #include<queue> #define MAXN 755 using namespace std; int n; int ans[MAXN]; int a[MAXN]; struct Node{ int Val,y; Node(int p1=0,int p2=0){ Val=p1,y=p2; } friend bool operator < (const Node &p1,const Node &p2){ return (p1.Val>p2.Val); } }; void Merge(){ priority_queue<Node> q; for(int i=1;i<=n;i++){ q.push(Node(ans[i]+a[1],1)); } for(int i=1;i<=n;i++){ Node x=q.top();q.pop(); ans[i]=x.Val; if(x.y<n){ q.push(Node(x.Val-a[x.y]+a[x.y+1],x.y+1)); } } } void solve(){ for(int i=1;i<=n;i++){ scanf("%d",&ans[i]); } sort(ans+1,ans+n+1); for(int i=2;i<=n;i++){ for(int j=1;j<=n;j++){ scanf("%d",&a[j]); } sort(a+1,a+n+1); Merge(); } for(int i=1;i<=n;i++){ printf("%d",ans[i]); if(i<n)printf(" "); } printf("\n"); } int main() { while(~scanf("%d",&n)){ solve(); } return 0; }
标签:sum span include top sort int max names pop
原文地址:http://www.cnblogs.com/w-h-h/p/7894713.html