解题思路
原来POJ用STL会T…
对每个组合,读进来之后先把 5 个数排序,拼成 15 位的数,之后去统计每个数出现的次数。
参考代码
#include<stdio.h>
#include<iostream>
#include<vector>
#include<cstring>
#include<cstdio>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<stack>
#define LL long long
#define LOCAL
const int maxn = 1e4 + 10;
using namespace std;
int readint() {
int x; scanf("%d", &x); return x;
}
int tmp[10];
LL num[maxn];
int cnt[maxn];
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n;
while (~scanf("%d", &n) && n) {
for(int i = 0; i < n; i++) {
for(int k = 0; k < 5; k++){
cnt[k] = readint();
}
sort(cnt, cnt + 5);
LL val = 0;
for(int j = 0; j < 5; j++) {
val = val * 1000 + cnt[j];
}
num[i] = val;
}
sort(num, num + n);
int k = 1, ccnt = 0;
for(int i = 0; i + 1 < n; i++) {
if (num[i] == num[i + 1]) k++;
else {
cnt[ccnt++] = k;
k = 1;
}
}
cnt[ccnt++] = k;
int ansm = 0, ans = 0;
for(int i = 0; i < ccnt; i++) {
if (cnt[i] == ansm) ans++;
if (cnt[i] > ansm) {
ansm = cnt[i];
ans = 1;
}
}
printf("%d\n", ans * ansm);
}
return 0;
}