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 ...
随机推荐
- Oracle数据库函数总结
1.ceil()向上取整,结果为124.select ceil(123.123) from dual;2.floor()向下取整,结果为123.select floor(123.123) from d ...
- CSS3D动画制作一个3d旋转的筛子
希望这个demo能让大家理解CSS3的3d空间动画(其实是个假3D) 首先给一个3d的解剖图,x/y/z轴线轴线已经标出 下面附上添加特效的动画旋转 可以根据demo并参考上面解剖图进行理解 < ...
- ArcGIS10.3+Oracle12C+ArcGIS Server10.3安装布署(之三)
1.将Oracle的客户端切换到64位 (1)将C:\下的instantclient_12_1目录重命名为instantclient_12_1X86 (2)从Oracle的官方网站下载 insta ...
- linux 搜索文件内容并输出命令 grep、-i、-v ^#
grep /bin/grepgrep -iv [指定字条串] [文件]在文件中搜索字符串匹配的行并输出-i 不区分大小写 -v 排除指定字符串 grep -i java /etc/profile gr ...
- oracle exp dmp
exp help=yconn scott/tiger;select * from tab;create table student(sno int, sname varchar2(10), sage ...
- mysql 客户端
MySQL是基于C/S模式的数据库管理系统.MySQL公司开发了众多的客户端软件来帮助用户管理MySQL软件,最著名的就是 MySQL Command Line Client 和 MySQL-Work ...
- SSH入门常用命令
一.参考链接大猫的博客
- java vector的多线程安全是否有用
在网上搜了不少文章,发现有不少没讲清楚的,也有不少好文,本文希望更易懂地描述该问题.如有不对的地方,请多多指正~~ vector的使用主要有如下两种场景:(1)vector所谓的多线程安全,只是针对单 ...
- 让两个对象间建立weak关系
让两个对象间建立weak关系 这是为了给两个对象间建立weak关系,当一个对象被释放时,另外一个对象再获取这个值时就是nil,也就是不持有这个对象:) 源码: WeakRelatedDictionar ...
- (转)光照模型及cg实现
经典光照模型(illumination model) 物体表面光照颜色由入射光.物体材质,以及材质和光的交互规律共同决定. 由于环境光给予物体各个点的光照强度相同,且没有方向之分,所以在只有环境光的情 ...