【HDOJ】1310 Team Rankings

STL的应用,基本就是模拟题。

 /* 1410 */
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
using namespace std; #define ONLINE_JUDGE
#define MAXN 125
#define INF 0xfffffff int nn;
int dis[MAXN][MAXN];
string buf[MAXN];
bool visit[];
map<string, int> tb;
int a[MAXN]; int myabs(int x) {
return x< ? -x:x;
} void init() {
string s = "ABCDE";
nn = ;
int i, j, k, p;
int sum, tmp; do {
buf[nn] = s;
tb[s] = nn++;
} while (next_permutation(s.begin(), s.end())); for (i=; i<nn; ++i) {
dis[i][i] = ;
for (j=i+; j<nn; ++j) {
sum = ;
memset(visit, false, sizeof(visit));
for (k=; k<; ++k) {
for (p=; p<; ++p) {
if (buf[j][p] == buf[i][k])
break;
else if (!visit[buf[j][p]-'A'])
++sum;
}
visit[buf[i][k]-'A'] = true;
}
dis[i][j] = dis[j][i] = sum;
}
}
} int main() {
int n;
int i, j, k, tmp;
int v, mmin, sum;
string s; ios::sync_with_stdio(false); #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif init();
while (cin>>n && n) {
for (i=; i<n; ++i) {
cin >>s;
a[i] = tb[s];
}
mmin = INF;
for (i=; i<nn; ++i) {
sum = ;
for (j=; j<n; ++j)
sum += dis[i][a[j]];
if (sum < mmin) {
v = i;
mmin = sum;
}
}
printf("%s is the median ranking with value %d.\n", buf[v].c_str(), mmin);
} return ;
}
上一篇:centos下yum安装crontab+mysql自动备份


下一篇:atitit。企业的价值观 员工第一 vs 客户第一.docx