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 numbernof a player's eigenvalues<nobr>(1 ≤<em>n</em>≤ 4000)</nobr>. In the second line
you are givenndistinct integers in ascending order, which are the eigenvalues. All the eigenvalues are positive integers not exceeding109.
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
|
即比较三个数组有多少相同的数字:
可以时间效率是O(n),n是最小数组的长度
#include <vector>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
void PsychUpEigenvalues()
{
int t1 = 0, t2 = 0, t3 = 0;
cin>>t1;
vector<int> v1(t1);
for (int i = 0; i < t1; i++)
{
cin>>v1[i];
}
cin>>t2;
vector<int> v2(t2);
for (int i = 0; i < t2; i++)
{
cin>>v2[i];
}
cin>>t3;
vector<int> v3(t3);
for (int i = 0; i < t3; i++)
{
cin>>v3[i];
}
int c = 0;
for (int i = 0, j = 0, k = 0; i < t1 && j < t2 && k < t3; )
{
int t = min(v1[i], min(v2[j], v3[k]));
if (t == v1[i] && t == v2[j] && t == v3[k])
{
c++, i++, j++, k++;
}
else if (t == v1[i]) i++;
else if (t == v2[j]) j++;
else k++;
}
cout<<c<<endl;
}
分享到:
相关推荐
acm.timus.ru最全代码
Timus ... Problems code. (Mainly Java implementation) Chinese 刷题代码,主要是java实现,可能会有其他语言代码 代码来自LeetCode / NowCoder / timus 等 site url LeetCode NowCoder Timus LeetCode-cn
acm.timus.ru解决方案 这些是我对ACM.TIMUS.RU问题的解决方案
timus.ru_solutions 使用的语言:Python 使用的Python版本:3.9 我可以用Python语言解决的一些问题在“ python”目录中。 有些解决方案可以在Java中运行,但确切的解决方案/算法在Python中不起作用! 不知道为什么我...
acm.timus.ru 1709 problem
timus.ru_solutions_python 使用的python:3.9 我可以用Python语言解决的一些问题在python目录中。 有些解决方案可以在Java中运行,但确切的解决方案/算法在Python中不起作用! 我不知道为什么
资源分类:Python库 所属语言:Python 资源全名:timus-sender-0.1.1.post1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Timus上习题解答与代码参考,这一部分对应于Timus上的Beginner部分的习题
timus:Timus在线法官问题
将图表添加到Timus Online Judge配置文件 该扩展程序将已解决问题的数量图表添加到Timus Online Judge的个人资料和比较器中。 功能:*概要文件和比较中已解决问题计数的图表*向图表中添加更多用户,删除它们,自定义...
Timus图表 将图表添加到Timus Online Judge个人资料中 特征 概要文件中和比较期间已解决问题的计数图表 向图表添加更多用户,删除它们,自定义图例颜色 缓存配置文件数据 隐藏图表 (可选)突出显示最近两个月内接受...
timus OJ 1197 lonesome kinght
蒂莫斯 该文件夹包含用Python编写的文件(主要是Python2.7,有些是Python3.4)我通过这些文件在timus上通过了相应的测试。
http://acm.timus.ru 俄罗斯乌拉尔大学在线题库 SGU http://acm.sgu.ru/ 俄罗斯圣萨拉托夫州大学在线题库 ELJ http://acm.mipt.ru/judge/bin/problems.pl?lang=en file:///M|/acm/ACM大量习题题库及建议培养计划.txt...
timus-online-judge Timus Online Judge 是俄罗斯最大的带有自动评判系统的编程问题档案。 问题主要是从在乌拉尔联邦大学、乌拉尔锦标赛、乌拉尔 ACM ICPC 次区域比赛和彼得罗扎沃茨克训练营举办的比赛中收集的。 ...
http://acm.timus.ru/problem.aspx?space=1&num=1362 一道树形动态规划的题目解答,ural1362
语言:English将图表添加到Timus Online Judge个人资料中该扩展程序将已解决问题的数量图表添加到Timus Online Judge的个人资料和比较器中。功能:*概要文件和比较中已解决问题计数的图表*向图表中添加更多用户,删除...
Pascal acm_timus_ural_1148.pas
Pascal acm_timus_ural_1099.pas
1. 介绍了一些著名的综合性OJ网站,如UVa、POJ、Timus、SGU等,题目数量大、种类全面。 2. 推荐了针对新手入门的OJ网站,如HDU、ZJU等,收集了不少水题,适合新手起步训练。 3. 介绍了一些以赛事见长的OJ网站,如...