URAL 1880 Psych Up's Eigenvalues (技巧)
2015-03-04 19:15
239 查看
Psych Up's Eigenvalues
Time limit: 0.5 secondMemory limit: 64 MB
At one of the contests at the Petrozavodsk Training Camp, players of the Psych Up team quickly found the simple problem and Fedya sat at the computer. The solution was 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 room slamming the door behind him. Things were going the wrong way and he needed to wind down. On his way to the 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 that 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 travels
to contests. But they had a team contest, so what was their team's eigenvalue? Of course, a number was a team's eigenvalue if it was an eigenvalue for each of its players. With these joyful thoughts Fedya returned to the contest room.
Input
The input data consist of three blocks two lines each. The first line of each block contains the number n of a player's eigenvalues (1 ≤ n ≤ 4 000). In the second lineyou are given n distinct integers in ascending order, which are the eigenvalues. All the eigenvalues are positive integers not exceeding 109.
Output
Output the number of eigenvalues of the Psych Up team.Sample
input | output |
---|---|
5 13 20 22 43 146 4 13 22 43 146 5 13 43 67 89 146 | 3 |
解析:由于数太大,所以不能直接开个数组去统计个数,但是可以用map建立从int到int的映射,这样就不用考虑数太大不能当下表统计的烦恼了。
AC代码:
#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; //统计出现的个数 } } printf("%d\n", ans); return 0; }
相关文章推荐
- URAL 1880 Psych Up's Eigenvalues
- [类欧几里得算法 数学技巧] 51Nod 1132 覆盖数字的数量 V2 & Ural 1797 Summit Online Judge. Version 2
- [URAL 1100]Final Standings(排序技巧)
- [求解二次剩余 数论技巧 随机化] Ural 1132 Square Root
- URAL 1880 Psych Up's Eigenvalues multiset水题
- vi 使用技巧(二): copy, paste, delete, 块编辑,redo/undo
- Visual Studio 2005 IDE 技巧和窍门
- Word技巧:轻松删除分节符
- 网站设计风格及色彩搭配技巧
- 60个常用word技巧
- SqlServer小技巧汇总
- Altium Designer Winter 09PCB布线使用技巧
- vim 使用技巧 <持续搜集>
- 经管资源库项目总结----数据库设计技巧
- Eclipse调试Bug的七种常用技巧
- Codeforces 110B-Lucky String(技巧)
- Linux shell用法和技巧
- Android开发之50个常见实用技巧——添加悦目的动画效果
- skynet 控制台管理使用技巧