// 读完题后,怀着忐忑的心情计算了一下我的思路,3*10^5 是不是有点过大...但没想到有什么好办法,先写上吧,结果,
  // 不解释了.
1 Source Code
2
3 Problem: 2038 User: eth1
4 Memory: 252K Time: 0MS
5 Language: C++ Result: Accepted
6 Source Code
7 #include <iostream>
8 #include <cstring>
9 #include <map>
10 #include <algorithm>
11 using namespace std;
12 map<char,int> mapp;
13 char ans[125][6];
14 int f[6],anss[125];
15 void init()
16 {
17 char s[6]="ABCDE";
18 int i=0;
19 do{
20 strcpy(ans[i++],s);
21 }while(next_permutation(s,s+5));
22 }
23 int main()
24 {
25 int n;
26 char s[6];
27 init();
28 while(cin>>n && n)
29 {
30 memset(anss,0,sizeof(anss));
31 for(int i=0;i<n;i++)
32 {
33 cin>>s;
34 for(int j=0;j<5;j++)
35 {
36 mapp[s[j]]=j;
37 }
38 for(int j=0;j<120;j++)
39 {
40 int tem=0;
41 for(int k=0;k<5;k++)
42 {
43 f[k]=mapp[ans[j][k]];
44 }
45 for(int k=0;k<5;k++)
46 {
47 for(int m=k+1;m<5;m++)
48 {
49 if(f[k]>f[m])
50 tem++;
51 }
52 }
53 anss[j]+=tem;
54 }
55 }
56 int maxx=10000000;
57 char s[6];
58 for(int i=0;i<120;i++)
59 {
60 if(anss[i]<maxx)
61 {
62 maxx = anss[i];
63 strcpy(s,ans[i]);
64 }
65 }
66 cout<<s<<" is the median ranking with value "<<maxx<<"."<<endl;
67 }
68 return 0;
69 }
 posted on 2011-05-10 15:35  eth0  阅读(184)  评论(0编辑  收藏  举报