1 solutions
-
0
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> #include<vector> #include<string> #include<map> #include <climits> using namespace std; int num[1005][15]; int bin[15]; int m, n; int cnt = 0; bool st[15]; void op() { while (1) { memset(bin, 0, sizeof(bin)); for (int i = 0; i < n; i++) { for (int t = 0; t < m; t++) { if (num[i][t] == 0) break; if (st[num[i][t]]) continue; bin[num[i][t]]++; break; } } int max = INT_MIN; int min = INT_MAX; for (int i = 0; i < 10; i++) { if (bin[i] > max&&!st[i]) max = bin[i]; if (bin[i] < min&&!st[i]) min = bin[i]; } if (max > min) { for (int i = 0; i <10 ; i++) { if (bin[i] == min&&st[i]==false) { st[i] = true; } } } else { int k = 0; for (int i = 0; i < 10; i++) { if (bin[i] == min && !st[i]) { cnt++; k = i; } } if (cnt == 1) { cout << k; return; } else { cout << -bin[k]; return; } } } } int main(void) { cin >> m >> n; for (int i = 0; i < n; i++) { string aa; cin >> aa; for (int t = 0; t < aa.size(); t++) num[i][t] = aa[t]-'0'; } op(); return 0; }
- 1
Information
- ID
- 1165
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- # Submissions
- 5
- Accepted
- 3
- Uploaded By