-
Notifications
You must be signed in to change notification settings - Fork 2
/
GCJ2014r1bA.cpp
113 lines (106 loc) · 1.85 KB
/
GCJ2014r1bA.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
ID: mfs6174
email: mfs6174@gmail.com
PROG: ti
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<cmath>
#include<set>
#define sf scanf
#define pf printf
#define llg long long
using namespace std;
ifstream inf("ti.in");
//ofstream ouf("ti.out");
//freopen("ti.in","r",stdin);
const int maxlongint=2147483647;
int i,j,k,t,n,m;
struct D
{
int id;
int len;
int shu[200],clen;
char code[200];
bool operator <(const D &x) const
{
return len<x.len;
}
};
D chuan[200];
string dd[200];
int op[200];
int main()
{
freopen("ti.out","w",stdout);
int zu;
inf>>zu;
for (int zz=1;zz<=zu;zz++)
{
inf>>n;
for (i=1;i<=n;i++)
{
inf>>dd[i];
chuan[i].id=i;
chuan[i].len=dd[i].size();
char t=-1;
chuan[i].clen=0;
for (j=0;j<dd[i].size();j++)
{
if (dd[i][j]!=t)
{
chuan[i].clen++;
chuan[i].code[chuan[i].clen]=dd[i][j];
chuan[i].shu[chuan[i].clen]=1;
t=dd[i][j];
}
else
{
chuan[i].shu[chuan[i].clen]++;
}
}
}
bool fail=false;
int rr=0;
for (int j=1;j<=chuan[1].clen;j++)
{
op[1]=chuan[1].shu[j];
for (i=2;i<=n;i++)
{
if (chuan[i].clen!=chuan[1].clen)
{
fail=true;
break;
}
if (chuan[i].code[j]!=chuan[1].code[j])
{
fail=true;
break;
}
op[i]=chuan[i].shu[j];
}
if (fail)
break;
sort(&op[1],&op[n+1]);
for (i=1;i<=n;i++)
rr+=abs(op[i]-op[n/2+1]);
}
if (fail)
{
pf("Case #%d: Fegla Won\n",zz);
}
else
pf("Case #%d: %d\n",zz,rr);
}
return 0;
}