codeforces 637A A. Voting for Photos(水题)
题目链接:
time limit per test
256 megabytes
standard input
standard output
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.
Help guys determine the winner photo by the records of likes.
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the total likes to the published photoes.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000), where ai is the identifier of the photo which got the i-th like.
Print the identifier of the photo which won the elections.
5
1 3 2 2 1
2
9
100 200 300 200 100 300 300 100 200
300
In the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3got one like (second).
Thus, the winner is the photo with identifier 2, as it got:
- more likes than the photo with id 3;
- as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+;
int flag[N],x[];
int main()
{
int n;
scanf("%d",&n);
memset(flag,,sizeof(flag));
for(int i=;i<n;i++)
{
scanf("%d",&x[i]);
flag[x[i]]++;
}
int ans=;
for(int i=;i<n;i++)
{
if(flag[x[i]]>ans)ans=flag[x[i]];
}
memset(flag,,sizeof(flag));
for(int i=;i<n;i++)
{
flag[x[i]]++;
if(flag[x[i]]==ans)
{
cout<<x[i]<<"\n";
break;
}
} return ;
}
codeforces 637A A. Voting for Photos(水题)的更多相关文章
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) A. Voting for Photos 水题
A. Voting for Photos 题目连接: http://www.codeforces.com/contest/637/problem/A Description After celebra ...
- codeforces Gym 100187H H. Mysterious Photos 水题
H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
- codeforces 707A A. Brain's Photos(水题)
题目链接: A. Brain's Photos 题意: 问是黑白还是彩色; 思路: 没有思路: AC代码: #include <iostream> #include <cstdio& ...
- 【Codeforces 707A】Brain's Photos 水题
黑白灰都是#Black&White #include <cstdio> int n,m; int main() { scanf("%d%d",&n,&a ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
随机推荐
- FreeSWITCH 基础
[1]FreeSWITCH 是什么? FreeSWITCH是一个开源的电话交换平台. 世界上第一个跨平台的.伸缩性极好的.免费的.多协议的电话软交换平台. 从技术上讲,FreeSWITCH是一个B2B ...
- Xampp 环境问题集合
1.不小心把虚拟机的环境删了,需要重新安装xmapp 安装很简单,但是重启:/opt/lampp/lampp restart 发现 XAMPP:"Another web server dae ...
- 生成n个元素的全排列 C实现
近期在准备复习算法设计的考试,下边记录一些,看笔记时突然想到的解法. 问题是这种 用递归实现 n 个元素的全排列. 当时老师给出的解答是 假定第i个元素 ri 放在首位,于是 f(r1,r2,-,rn ...
- c#中关于compare比较的一点注意事项
一直没有太注意,今天发现在compare比较两个字符串的时候出了点小问题 如果我设置了两个字符串 一个是“2”,一个是“12” 那么在比较的时候 第一个会大于第二个: 如果第一个是“02”,第二个是“ ...
- spring+thymeleaf实现表单验证数据双向绑定
前言 这个教程介绍了Thymeleaf与Spring框架的集成,特别是SpringMvc框架. 注意Thymeleaf支持同Spring框架的3.和4.版本的集成,但是这两个版本的支持是封装在thym ...
- Django 路飞学成书写规范的总结
路飞学成书写规范的总结 命名 项目/文件/函数 -> 小写+下划线 类 驼峰式 路由 将每个功能的路由进行分割, 或者做上注释 类和方法的注释 每个类都要注释是干什么的 每个方法也要进行注释标明 ...
- LeetCode:快乐数【202】
LeetCode:快乐数[202] 题目描述 编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数 ...
- float后怎么居中
我们在用css float的时候,如何让文本水平居中真的很麻烦, [float]使div(或者其他标签)的宽度自适应其内容,但它却有个弊端:无法居中.[display:inline-block]也有同 ...
- pyspark
http://www.aboutyun.com/thread-18150-1-1.html
- oracle 序列 + 触发器 实现 ID自动增长
1.创建序列 create sequence emp_sequence increment by ----每次增加几个 minvalue ----最小值为1 nomaxvalue----不限制最大值 ...