Educational Codeforces Round 24 D
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like this. Firstly Alice chooses some color A, then Bob chooses some color B (A ≠ B). After each car they update the number of cars of their chosen color that have run past them. Let's define this numbers after i-th car cntA(i) and cntB(i).
- If cntA(i) > cntB(i) for every i then the winner is Alice.
- If cntB(i) ≥ cntA(i) for every i then the winner is Bob.
- Otherwise it's a draw.
Bob knows all the colors of cars that they will encounter and order of their appearance. Alice have already chosen her color A and Bob now wants to choose such color B that he will win the game (draw is not a win). Help him find this color.
If there are multiple solutions, print any of them. If there is no such color then print -1.
The first line contains two integer numbers n and A (1 ≤ n ≤ 105, 1 ≤ A ≤ 106) – number of cars and the color chosen by Alice.
The second line contains n integer numbers c1, c2, ..., cn (1 ≤ ci ≤ 106) — colors of the cars that Alice and Bob will encounter in the order of their appearance.
Output such color B (1 ≤ B ≤ 106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1.
It is guaranteed that if there exists any solution then there exists solution with (1 ≤ B ≤ 106).
4 1
2 1 4 2
2
5 2
2 2 4 5 3
-1
3 10
1 2 3
4
Let's consider availability of colors in the first example:
- cnt2(i) ≥ cnt1(i) for every i, and color 2 can be the answer.
- cnt4(2) < cnt1(2), so color 4 isn't the winning one for Bob.
- All the other colors also have cntj(2) < cnt1(2), thus they are not available.
In the third example every color is acceptable except for 10.
题意:两个人玩游戏,额,两个人分别选一个数字,现在我们让B赢,规则是
当前位置上,所选的数字比另外一个选的数字出现次数多或者一样就算这个位置胜利了,从头到尾一直是B胜利就行
比如 2 1 4 2 A选了1 B选2
2在第一位出现一次,1没有出现,第一位胜利
2在第二位没有出现,1出现一次,一共是1:1,也是胜利
第三位两个数字都没有,1:1,胜利
第四位2出现,最后是2:1 胜利
解法:
1 必输的情况,A把第一个数字选了
2 必胜的情况,A没有选C数组任何一个,那么我们随便选一个就行
3 如果某一个数字曾经输于A,则不选
比如 A选2
3 2 2 2 3 那么3输了,不能选3
4 B不能选和A相同的数字,且出现次数比A选的数字要多。经过第3点的过滤,出现符合第4点的数字立马输出就行
#include<bits/stdc++.h>
using namespace std;
const long long N = 1e6+;
vector<long long>v[];
set<int>P;
long long A[N];
map<int,int>Q,Mp;
int main()
{
int num,a;
int flag=;
scanf("%d%d",&num,&a); for(int i=;i<=num;i++){
scanf("%d",&A[i]); if(A[i]==a){
flag=;
}
if(Q[A[i]]<Q[a]){
Mp[A[i]]=-;
}
Q[A[i]]++;
}
if(A[]==a){
printf("-1");
return ;
}
if(flag==){
for(int i=;i<N;i++){
if(Q[A[i]]>=Q[a]&&Mp[A[i]]!=-&&A[i]!=a){
printf("%d",A[i]);
return ;
}
}
printf("-1");
return ; }else{
printf("%d",A[]);
}
return ;
}
Educational Codeforces Round 24 D的更多相关文章
- Educational Codeforces Round 24 A 水 B stl C 暴力 D stl模拟 E 二分
A. Diplomas and Certificates time limit per test 1 second memory limit per test 256 megabytes input ...
- Educational Codeforces Round 24 CF 818 A-G 补题
6月快要结束了 期末也过去大半了 马上就是大三狗了 取消了小学期后20周的学期真心长, 看着各种北方的学校都放假嗨皮了,我们这个在北回归线的学校,还在忍受酷暑. 过年的时候下定决心要拿块ACM的牌子, ...
- Educational Codeforces Round 24 E
Vova again tries to play some computer card game. The rules of deck creation in this game are simple ...
- codeforces Educational Codeforces Round 24 (A~F)
题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...
- Educational Codeforces Round 24
A. Diplomas and Certificates time limit per test 1 second memory limit per test 256 megabytes input ...
- Educational Codeforces Round 24 B
n children are standing in a circle and playing a game. Children's numbers in clockwise order form a ...
- Educational Codeforces Round 24 A
There are n students who have taken part in an olympiad. Now it's time to award the students. Some o ...
- Educational Codeforces Round 24 题解
A: 考你会不会除法 //By SiriusRen #include <bits/stdc++.h> using namespace std; #define int long long ...
- Educational Codeforces Round 32
http://codeforces.com/contest/888 A Local Extrema[水] [题意]:计算极值点个数 [分析]:除了第一个最后一个外,遇到极值点ans++,包括极大和极小 ...
随机推荐
- linux led子系统(二)
对于led子系统中,有那么多得trigger,下面就来简单了解下. 1.default-on static void defon_trig_activate(struct led_classdev * ...
- linux led子系统(一)
就像学编程第一个范例helloworld一样,学嵌入式,单片机.fpga之类的第一个范例就是点亮一盏灯.对于庞大的linux系统,当然可以编写一个字符设备驱动来实现我们需要的led灯,也可以直接利用g ...
- nodejs什么值得买自动签到自动评论定时任务
本项目是基于nodejs开发,实现的功能是,什么值得买自动签到,自动评论功能,自动发邮件,支持多人多账号运行 目的是为了,解放双手,轻松获取什么值得买的经验和积分,得到更高的等级,从而突破很会员等级限 ...
- Hibernate Jar包官方下载
1.新手入门,从官网下载Hibernate,选择 Hibernate ORM 2.选择Releases-Overview 3.上面列出的是最新版本,下面有一个see older series 直接下载 ...
- 通过反射调用一个单列的方法(单列必须有“getInstance”方法)
Class<?> _clazz = Class.forName(_clazzName); if (_clazz != null) { Method _getInstance = _claz ...
- queue — A synchronized queue class
https://docs.python.org/3.6/library/queue.html https://github.com/python/cpython/blob/3.6/Lib/queue. ...
- SpringMVC 之 Controller、Service层职责
Controller层 1.接收httpRequest/requestDTO数据 ,检查接收数据参数与格式. 2.传递参数至Service层并接收返回responseDTO数据. 3.包装respon ...
- java 相关博客
Intellij Idea 创建Web项目入门(一) SpringMVC 和 MyBatis 学习笔记,搭配示例,主要讲解一些基础的概念.用法和配置 包含框架有:SpringMVC.MyBaits.A ...
- java 获取项目根目录
代码入下: request.getSession().getServletContext().getRealPath(); 这里的getRealPath()括号里面可以输入你想得到的具体目录. 需要注 ...
- sdut oj 1510 Contest02-4 Spiral
Contest02-4 Spiral Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Given an odd number n, ...