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

脑残了,,,next_permutation给忘掉了,,,做了5个for,,,,

Posted by yy17yy at 2011-04-20 19:59:08 on Problem 2038
#include <iostream>
using namespace std;
const int N=111;
int n;
int hsh[N];
char w[N][N];
int get()
{
	int i,j,k,ans=0;
	for(k=1;k<=n;k++)
		for(i=2;i<=5;i++)
			for(j=1;j<i;j++)
				if(hsh[w[k][j]]>hsh[w[k][i]])
					ans++;
	return ans;
}
int main()
{
	while(scanf("%d",&n),n)
	{
		int i;
		for(i=1;i<=n;i++)
			scanf("%s",w[i]+1);
		int i1,i2,i3,i4,i5,ans=INT_MAX,a1,a2,a3,a4,a5;
		for(i1=0;i1<5;i1++)
			for(i2=0;i2<5;i2++)
				if(i2!=i1)
					for(i3=0;i3<5;i3++)
						if(i3!=i1&&i3!=i2)
							for(i4=0;i4<5;i4++)
								if(i4!=i1&&i4!=i3&&i4!=i2)
									for(i5=0;i5<5;i5++)
										if(i5!=i1&&i5!=i2&&i5!=i3&&i5!=i4)
										{
											hsh[i1+'A']=1;
											hsh[i2+'A']=2;
											hsh[i3+'A']=3;
											hsh[i4+'A']=4;
											hsh[i5+'A']=5;
											int tmp=get();
											if(ans>tmp)
												ans=tmp,a1=i1,a2=i2,a3=i3,a4=i4,a5=i5;
										}
		printf("%c%c%c%c%c is the median ranking with value %d.\n",a1+'A',a2+'A',a3+'A',a4+'A',a5+'A',ans);
	}
	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