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

又忘了添#include<string>结果CE两次……

Posted by YushengJiang at 2012-08-30 12:02:50 on Problem 1789
算是贡献了。
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int father[2000];
struct road{
	int from,to;
	int dist;
} roads[4000000];
string data[2000];
int searchfather(int i){
	if (father[i]==i) return i;
	return father[i]=searchfather(father[i]);
}
bool cmp(road a,road b){
	return a.dist<b.dist;
}
int main (void){
	int n,rd;
	cin>>n;
	while (n!=0){
		for (int i=0;i<n;++i){
			father[i]=i;
			cin>>data[i];
		}
		int rd=0;
		for (int i=0;i<n-1;++i)
			for (int j=i+1;j<n;++j){
				roads[rd].from=i;
				roads[rd].to=j;
				roads[rd].dist=0;
				for (int k=0;k<7;++k) roads[rd].dist+=data[i][k]==data[j][k]?0:1;
				++rd;
			}
		sort(&roads[0],&roads[rd],cmp);
		int pt=0,ct=0,tot=0;
		while (pt!=n-1){
			while (searchfather(roads[ct].from)==searchfather(roads[ct].to)) ++ct;
			father[searchfather(roads[ct].from)]=searchfather(roads[ct].to);
			tot+=roads[ct].dist;
			++pt;
			++ct;
		}
		cout<<"The highest possible quality is 1/"<<tot<<"."<<endl;
		cin>>n;
	}
	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