443 B. Table Tennis
For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
The first line contains two integers: n and k (2 ≤ n ≤ 500, 2 ≤ k ≤ 1012) — the number of people and the number of wins.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ai are distinct.
Output a single integer — power of the winner.
2 2
1 2
2
4 2
3 1 2 4
3
6 2
6 5 3 1 2 4
6
2 10000000000
2 1
2
Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.
简单题,注意k很大,当k>n时,输出最大的那个就行
#include <bits/stdc++.h>
using namespace std;
#define maxn 100000
typedef long long ll;
#define inf 2147483647
#define ri register int
vector<ll> vec;
ll p[maxn];
ll cnt[maxn];
ll n, k;
ll ma = ; int main() {
// freopen("test.txt", "r", stdin);
cin >> n >> k;
for (int i = ; i <= n; i++) {
cin >> p[i];
ma = max(ma, p[i]);
vec.push_back(i);
}
if (k > n) {
cout << ma;
return ;
}
while () {
// for(ll i:vec)cout<<i<<" ";
// cout<<endl;
int t1 = vec.front();
vec.erase(vec.begin());
int t2 = vec.front();
vec.erase(vec.begin());
if (p[t1] > p[t2]) {
cnt[t1]++;
if (cnt[t1] == k) {
cout << p[t1];
return ;
}
vec.push_back(t2);
vec.insert(vec.begin(), t1);
} else {
cnt[t2]++;
if (cnt[t2] == k) {
cout << p[t2];
return ;
}
vec.push_back(t1);
vec.insert(vec.begin(), t2);
}
} return ;
}
443 B. Table Tennis的更多相关文章
- PAT 1026. Table Tennis
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For ...
- 1026. Table Tennis (30)
题目如下: A table tennis club has N tables available to the public. The tables are numbered from 1 to N. ...
- PAT A1026 Table Tennis (30 分)——队列
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) C. Table Tennis Game 2 水题
C. Table Tennis Game 2 题目连接: http://codeforces.com/contest/765/problem/C Description Misha and Vanya ...
- PAT 1026 Table Tennis[比较难]
1026 Table Tennis (30)(30 分) A table tennis club has N tables available to the public. The tables ar ...
- Table Tennis Game 2(找规律)
Description Misha and Vanya have played several table tennis sets. Each set consists of several serv ...
- PAT甲级1026. Table Tennis
PAT甲级1026. Table Tennis 题意: 乒乓球俱乐部有N张桌子供公众使用.表的编号从1到N.对于任何一对玩家,如果有一些表在到达时打开,它们将被分配给具有最小数字的可用表.如果所有的表 ...
- PAT 甲级 1026 Table Tennis(模拟)
1026. Table Tennis (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A table ...
- PAT 1026 Table Tennis (30)
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
随机推荐
- MySql基本学习知识点:
1.Mysql的简介: (1):常识: MySQL是一种关系数据库管理系统,是一种开源软件 由瑞典MySQL AB公司开发,2008年1月16号被Sun公司收购.2009年,SUN又被Oracle收购 ...
- c# 异步和同步问题(转载)
[C#] 谈谈异步编程async await 为什么需要异步,异步对可能起阻止作用的活动(例如,应用程序访问 Web 时)至关重要. 对 Web 资源的访问有时很慢或会延迟. 如果此类活动在同步过 ...
- Java 简化版学生管理系统(IO版)
Student management system 学生管理系统IO版 详细知识点可参考一下几篇文章 常用API Java 之ArrayList集合及应用 Java 之IO流及应用 Compreh ...
- SLAM会被深度学习方法取代吗?
日益感觉到自己对深度学习的理解比较肤浅,这段且当做是以前的认识. 上上周去围观了泡泡机器人和AR酱联合举办的论坛.在圆桌阶段,章国峰老师提了一个问题:SLAM会被深度学习方法取代吗?这是一个很有趣的话 ...
- git 错误error: failed to push some refs to
今天使用VSCODE 学习node.js, 想在git上push代码 于是在git上建立了一个私有的长裤, 连接后push代码时提示如下错误: error: failed to push some ...
- ew代理实战
前言 渗透内网代理必不可少,本文做个记录 正文 工具下载地址 http://rootkiter.com/EarthWorm/ ssocksd开启 socks5 代理 环境 代理:192.168.211 ...
- 【转】SSL协议详解
作者:朱祁林 出处:http://zhuqil.cnblogs.com 原文链接 背景介绍 最近在看<密码学与网络安全>相关的书籍,这篇文章主要详细介绍一下著名的网络安全协议SSL. ...
- Week3——文档代码分析
该段代码代码显示了不使用异步处理的基本servlet: @WebServlet(urlPatterns={"/syncservlet"}) public class SyncSer ...
- springMVC入门-03
接着上一讲介绍springMVC针对rest风格的支持. 查询数据 使用前:/user_show?id=120 使用后:/user/120 删除数据 使用前:/user_delete?id=123 使 ...
- 解决 There are no resources that can be added or removed from the server
网上下载了一个项目,在eclipse中部署时,加载项目到tomcat中项目名称无法显示,报出There are no resources that can be added or removed fr ...