题目大意:已知一队网球运动员,排成一队,一开始前两个运动员比赛,输的人到队尾,赢的人继续和队头比赛。
问那个运动员先获得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);
}
}
}