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 ...
随机推荐
- Android Studio中常用设置
参考资料: 1.http://blog.csdn.net/itdada/article/details/43375893 常用设置: 1.Tab不用4个空格Code Style->Java-&g ...
- ajax Form提交与Payload提交
后端处理前端提交的数据时,既可以使用Form解析,也可以使用JSON解析Payload字符串. Form解析可以直接从Request对象中获取请求参数,这样对象转换与处理相对容易,但在大片JSON数据 ...
- eclipse导入web工程变成Java工程,解决方案
经常在eclipse中导入web项目时,出现转不了项目类型的问题,导入后就是一个java项目. 解决步骤: 1.进入项目目录,可看到.project文件,文本编辑器打开. 2.找到<nature ...
- linux下apache php配置redis
1.安装redis 第一步: 下载:https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz 上传phpredis-2.2.4.tar.gz ...
- 杭电OJ(HDU)-ACMSteps-Chapter Three-《FatMouse' Trade》《今年暑假不AC》《排名》《开门人和关门人》
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2Fpc2luaV92Yw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- linux 下配置jdk
去java官方地址下载相应的源码包我下载的是1.8.0放在usr/local目录下 export JAVA_HOME=/usr/local/jdk1.8.0export PATH=$JAVA_HOME ...
- Zookeeper数据与存储
一.前言 前面分析了Zookeeper对请求的处理,本篇博文接着分析Zookeeper中如何对底层数据进行存储,数据存储被分为内存数据存储于磁盘数据存储. 二.数据与存储 2.1 内存数据 Zooke ...
- 软RAID5制作流程
说明:本实验没有用到多个磁盘,而是利用单个磁盘划分出的多个分区来仿真的,如果在实际项目中,请依情况而定. 1. 分区 我这里划分6个分区,用4个分区组成RAID 5,用1个分区作为spare disk ...
- 2017-2018-1 20179209《Linux内核原理与分析》第九周作业
理解进程调度时机 进程调度时机 中断处理过程(包括时钟中断.I/O中断.系统调用和异常)中,直接调用schedule(),或者返回用户态时根据need_resched标记调用schedule(): 内 ...
- CentOS查看和修改MySQL字符集
通过以下命令查看了MySQL的字符集 连接上mysql服务,输入以下命令 mysql>show variables like 'character_set%'; 显示如下: 为了让MySQL支持 ...