Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A留念

Posted by songruirui at 2013-04-24 10:21:44 on Problem 2442
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <queue>
using namespace std;
const int MAX=2001;
int aseq[MAX+1];
int tempseq[MAX+1];
struct e
{
	int v;
	int id;
	
};
struct cmp
{
	bool operator() (e a,e b)
	{
		return a.v>b.v;
	}
};
int main()
{
	int rounds;
	int m,n;
	scanf("%d",&rounds);
	while(rounds--)
	{
		//读入一个seq到aseq中,将其排序
		scanf("%d%d",&m,&n);
		for(int i=1;i<=n;i++)
			scanf("%d",&aseq[i]);
		sort(aseq+1,aseq+n+1);
		//读入第二个seq,与aseq[1]想加加入到优先队列中
		priority_queue<e,vector<e>,cmp>mq;
		for(int i=2;i<=m;i++)
		{
			while(mq.empty()==false)
				mq.pop();
			e temp;
			temp.id=1;
			for(int i=1;i<=n;i++)
			{
				scanf("%d",&temp.v);
				temp.v+=aseq[1];
				
				mq.push(temp);
			}
			for(int i=1;i<=n;i++)
			{
				temp=mq.top();
				mq.pop();
				int k=aseq[temp.id];
				tempseq[i]=temp.v;
				temp.v=temp.v-k+aseq[temp.id+1];
				temp.id++;
				mq.push(temp);
			}
			memcpy(aseq,tempseq,sizeof(aseq));
		}
		for(int i=1;i<=n;i++)
			cout<<aseq[i]<<" ";
		cout<<endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator