您的位置:首页 > 其它

*team ranking

2020-02-17 12:18 956 查看
    // 读完题后,怀着忐忑的心情计算了一下我的思路,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 }

转载于:https://www.cnblogs.com/eth0/archive/2011/05/10/2042191.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
aimei3954 发布了0 篇原创文章 · 获赞 0 · 访问量 254 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: