思科 9.20 笔试代码题
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin >> n >> m;
vector<int> nums(n, 0);
vector<bool> vis(n, false);
vector<char> ret(n, 0);
map<int, int, greater<int>> hash;
for(int i = 0;i < n;i++)
{
cin >> nums[i];
hash.insert({nums[i], i});
}
char cur = 'A';
auto it = hash.begin();
while(it != hash.end())
{
int max_index = it->second;
if(vis[max_index])
{
it++;
continue;
}
ret[max_index] = cur;
vis[max_index] = true;
int i = 0;
while(max_index+1 < n && i < m )
{
if(!vis[max_index + 1])
{
i++;
vis[max_index+1] = true;
ret[max_index+1] = cur;
}
max_index++;
}
i = 0;
max_index = it->second;
while(max_index-1 >= 0 && i < m )
{
if(!vis[max_index - 1])
{
i++;
vis[max_index-1] = true;
ret[max_index-1] = cur;
}
max_index--;
}
if(cur == 'A') cur = 'B';
else cur = 'A';
hash.erase(it++);
}
for(int i = 0;i < n;i++)
cout << ret[i];
return 0;
}
#思科#
