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 ...
随机推荐
- gulp入门实践
前言:大家可能都听说过gulp,知道它是一种前端自动化开发工具,可以用来文件压缩.语法检查.文件合并和编译less等,但可能并不知道要怎么用?看过官方文档,也看过许多博客,但基本都是讲gulp的API ...
- JavaScript正则表达式检验手机号码、邮箱、ip地址等
1)检测IP地址的正则表达式 ((2 [0-4] \d | 25[0-5] | [01]?\d\d?) \.){3}(2 [0-4] \d | 25[0-5] | [01]?\d\d?) 2 [0-4 ...
- Math.random理解练习
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Flutter的教程:ListView
本文学习一下列表widget,是最常见的需求 在Flutter中,用ListView来显示列表项,支持垂直和水平方向展示,通过一个属性我们就可以控制其方向 1.水平的列表 2.垂直的列表 3.数据量非 ...
- 【Python】Java程序员学习Python(十)— 类、包和模块
我觉得学习到现在应该得掌握Python的OOP编程了,但是现在还没有应用到,先留一个坑. 一.类和对象 说到类和对象其实就是在说面向对象编程,学完Java以后我觉得面向对象编程还是很不错的,首先封装了 ...
- hibernate的延迟加载和抓取策略
一,延迟加载 1.实体类延迟加载 通过代理机制完成,由javassist类库实现运行时代理,修改实体类的字节码实现了运行时代理 <class lazy="true|false& ...
- jquery中的ajax方法
$.ajax()方法详解 jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为Strin ...
- Jmeter入门--Badboy使用教程(转)
一.Badboy下载安装 感谢smxwn分享,转载地址:http://blog.csdn.net/wn_68/article/details/45872269 下载地址:http://www.badb ...
- iOS8中的定位服务
iOS8中的定位服务 My app that worked fine in iOS 7 doesn't work with the iOS 8 SDK. CLLocationManager doesn ...
- 11 个 Git 面试题
源自:https://mp.weixin.qq.com/s/ghF27N0XjgG0pw2XpGDCYA 在今年的 Stack Overflow 开发者调查报告中,超过 70% 的开发者使用 Git, ...