URAL 1880. Psych Up's Eigenvalues
2015-03-19 22:36
225 查看
1880. 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 |
手动了快排,因为sort没用明白,就任性了一把...
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; int a[1000001]; void qs(int left,int right) { int i,j,t,k; if(left>right) return; k=a[left]; i=left; j=right; while(i!=j) { while(a[j]>=k&&i<j) j--; while(a[i]<=k&&i<j) i++; if(i<j) { t=a[i]; a[i]=a[j]; a[j]=t; } } a[left]=a[i]; a[i]=k; qs(left,i-1); qs(i+1,right); } int main() { int n,ans=0,sum=0; for(int i=0;i<3;i++) { scanf("%d",&n); for(int j=ans;j<ans+n;j++) scanf("%d",&a[j]); ans+=n; } qs(0,ans-1); for(int i=0;i<ans;i++) { if(a[i]==a[i+1]&&a[i]==a[i+2]) sum++; } cout<<sum<<endl; return 0; }
相关文章推荐
- Ural 1880. Psych Up's Eigenvalues
- ural 1880. Psych Up's Eigenvalues 贪心
- corresponds to your MySQL server version for the right syntax to use near 'describe)values(225,0,'aa
- URAL 1800 Murphy's Law(物理判断题)
- LINUX TOMCAT 部署 两个项目 出现Choose unique values for the 'webAppRootKey' context-param in your web.xml
- 使用'VRM_SET_VALUES'函数在selection屏幕上建一个Combobox控件示例
- Values of attribute 'level' not equal in different manifest snippets-MFC链接问题
- matlab错误:Function 'conv2' is not defined for values of class 'double' and attributes
- Ural 1671. Anansi's Cobweb(并查集)
- $query = "insert into books values (' ".$isbn." ', ' ".$author." ', ' ".$title." ', ' ".$price." ')"
- URAL 1822. Hugo II's War 树的结构+二分
- URAL 1723. Sandro's Book(数学啊)
- URAL 1822. Hugo II's War 树的结构+二分
- Ural 1723. Sandro's Book
- Ural 1684. Jack's Last Word 多串KMP
- Eigen库对齐问题:declspec(align('16')) 的形参将不被对齐
- URAL 1353. Milliard Vasya's Function(dp)
- 使用'VRM_SET_VALUES'函数在selection屏幕上建一个Combobox控件示例
- URAL 1671 Anansi's Cobweb (并查集)
- URAL 1837. Isenbaev's Number (map + Dijkstra || BFS)