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

求助呀??

Posted by new_born at 2009-09-01 18:55:41 on Problem 2531
我的思路是将一个Cij看做一个整体,将矩上三角提出后按流量排序,然后从最大的Cij开始取。下面是我的代码:
#include<iostream>
#include<algorithm>
using namespace std;
struct pairs
{
	int from,to,number;
};
bool comp(pairs &rhs,pairs &lhs)
{
	return rhs.number>lhs.number;
}
pairs maps[400];
int part[30];
int main()
{
	int n,temp,count=0;
	memset(part,0,sizeof(part));
	cin>>n;
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	{
		cin>>temp;
		if(i>=j)continue;
		maps[count].from=i;
		maps[count].to=j;
		maps[count].number=temp;
		count++;
	}
	sort(maps,maps+count,comp);
	int sum=0;
	for(int t=0;t<count;t++)
	{
		if(part[maps[t].from]==0)
		{
			sum+=maps[t].number;
			if(part[maps[t].to]==0)
			{
				part[maps[t].from]=1;
				part[maps[t].to]=-1;
			}
			else if(part[maps[t].to]==1)part[maps[t].from]=-1;
			else part[maps[t].from]=1;
		}
		else if(part[maps[t].to]==0)
		{
			sum+=maps[t].number;
			if(part[maps[t].from]==1)part[maps[t].to]=-1;
			else if(part[maps[t].from]==-1)part[maps[t].to]=1;
		}
		else if(part[maps[t].from]!=part[maps[t].to])sum+=maps[t].number;
	 
	}
	cout<<sum<<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