#include<iostream>
using namespace std;
typedef struct Node {
int index;
int data;
}node;
const int N = 10010;
node a[N];
int output[N];
int hh = 1, tt = 0;
int cnt;
bool is_max(Node r[], Node s, int hh, int tt) {
for (int i = hh; i <= tt; i++) {
if (r[i].data > s.data) return false;
}
return true;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a[i].index = i;
a[i].data = x;
}
hh = 1, tt = n;
while (hh <= tt)
{
if (is_max(a, a[hh], hh, tt))
{
cnt++;
output[a[hh].index] = cnt;
hh++;
}
else
{
a[++tt] = a[hh++];
}
}
cout << output[m] << endl;
}
标签:Node,index,存储,下标,int,tt,永久,hh,data
From: https://www.cnblogs.com/windzhao6/p/18426989