Codeforces 879 B Table Tennis(模拟)

题目链接

题目大意:已知一队网球运动员,排成一队,一开始前两个运动员比赛,输的人到队尾,赢的人继续和队头比赛。

问那个运动员先获得k次胜利,输出该运动员的实力。

题目分析:单纯是数据吓人题,题目说了每个运动员实力都不同,如果k>n的时候队中所有人(最强的除外)在得到k次胜利之前都会遇到最强的人,从而达不到k次胜利。

而当最强的人获胜之后就可以一直赢下去知道他赢了k次。所以当k>n时直接输出最强的就行了。

当k<=n时候就老老实实模拟就行了。毕竟n<=500不会tle的。

代码如下

#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<set>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<cmath>
#include<stack>
#include<fstream>
//#define mod 1030
//#define size 3
using namespace std;
typedef long long LL;
const int maxn = (int)(2 * 1e4 + 100);
const int maxm = (int)(22222);
const int inf = (int)(1e9 * 2);
int win[550];
struct nodes {
	int pows, num;
	nodes() {}
	nodes(int a, int b) :pows(a), num(b) {}
}edge[550];
queue<nodes> que;
int main() {
	int n;
	LL k;
	while (scanf("%d%I64d", &n, &k) == 2) {
		int mp = -inf;
		while (!que.empty()) que.pop();
		memset(win, 0, sizeof(win));
		for (int i = 1; i <= n; i++) {
			scanf("%d", &edge[i].pows);
			edge[i].num = i;
			mp = max(mp, edge[i].pows);
			que.push(edge[i]);
		}
		if (k >= n)  printf("%d\n", mp);
		else {
			memset(win, 0, sizeof(win));
			nodes fir = que.front();
			int pos = 0;
			que.pop();
			while (win[pos] < k) {
				nodes tmp = que.front();
				que.pop();
				if (fir.pows > tmp.pows) {
					que.push(tmp);
					win[fir.num]++;
					pos = fir.num;
				}
				else {
					que.push(fir);
					win[tmp.num]++;
					fir = tmp;
					pos = fir.num;
				}
			}
			printf("%d\n", edge[pos].pows);
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值