Psych up ' s eigenvalues
Time limit:0.5 Second
Memory limit:64 MB
At one of the contests in the Petrozavodsk Training Camp, players of the Psych up team quickly found the simple problem a nd Fedya sat at the computer. The solution is ready in five minutes. Without spending time for testing, Fedya submitted it and in a few seconds got time Limit exceeded. Fedya crumpled the problem statement and left the hostel slamming the door behind him. Things were going the wrong and he needed to wind. On his restroom Fedya heard a conversation of the contest authors. Pasha was discussing with his friend, the solution of the problem for which Fedya had got TLE. Fedya could only discern the word "eigenvalues." Fedya thought about it and decided so he, for sure, had his eigenvalues. For example, the date of birth, the number of his apartment, the mark he had got at the latest exam, or the number of Trav Els to contests. But they had a team contest, so what is their team ' s eigenvalue? Of course, a number was a team ' s eigenvalue if it is an eigenvalue for each of its players. With these joyful thoughts Fedya returned to the contest.InputThe input data consist of three blocks and lines each. The first line of each block contains the number N of a player ' s eigenvalues (1≤n≤4 000). The second line is given n distinct integers in ascending order, which is the eigenvalues. All the eigenvalues is positive integers not exceeding 10 9.OutputOutput the number of eigenvalues of the Psych up team.Sample
input |
Output |
5
146
4
146
5
13 43 67 89 146
|
3
|
Test instructions: Find the number of the numbers in each of the three sequences.
Resolution: Because the number is too large, so you can not directly open the number of groups to statistics, but it is possible to use map to build a map from int to int, so that you do not have to consider the number too big can not be the current table statistics of the trouble.
AC Code:
#include <cstdio>
#include <map>
using namespace std;
Map<int, int> A;
int main () {
#ifdef sxk
freopen ("In.txt", "R", stdin);
#endif//sxk
int n, ans = 0, C;
while (~SCANF ("%d", &n)) {for
(int i=0; i<n; i++) {
scanf ("%d", &c);
Ans + = ++a[c] = = 3; Count the number of occurrences
}
}
printf ("%d\n", ans);
return 0;
}