当前位置:网站首页>Zcmu--1396: queue problem (2)
Zcmu--1396: queue problem (2)
2022-07-07 08:11:00 【Little why】
Description
One of them contains n Queues of elements q, The size of each element meets 1<=xi<=9(0<i<n). Queue has an operation , For the first element of the queue, if the whole queue is the largest, it will be out of the queue , Or join the tail of the team . For a given m, Can you tell me xm Is it the first one out of the queue ?
Input
The first line of input data is an integer T(1<=T<=1000), Represents the number of groups of input data ; The first row of each group of data is two positive integers n Represents the size of the queue and the number of elements (1<n<=1000,0<=m<n), The second line has n Number xi , Represent the size of each element respectively .
Output
For each group of test data , Output xm Is the number of queues .
Sample Input
3
1 0
5
4 2
1 2 3 4
6 0
1 1 9 1 1 1
Sample Output
1
2
5
analysis : We make use of set To quickly get the maximum element value in the current queue , Because there are elements that repeat , So we have to use multiset Come and save . We can use structures to store elements id and valu value ,c Indicates the number of out of line , If a[ i ]==st.*rbegin() Express a[ i ] Is the largest element in the current queue , List out , If it is xm, Then output c that will do , On the contrary, it is not the maximum , At the end of the team , Corresponding multiset Also delete this element in , So repeatedly until xm List out .
#include <stdio.h>
#include <set>
using namespace std;
struct su
{
int id;
int v;
}a[10005];
int main()
{
int t,i,n,k,c;
scanf("%d",&t);
while(t--){
multiset<int>st; // establish multiset
scanf("%d%d",&n,&k);
c=1; // Indicates the number of out of line
for(i=0;i<n;i++){
scanf("%d",&a[i].v);
a[i].id=i;
st.insert(a[i].v); // Deposit in set
}
for(i=0;i<n;i++){
if(a[i].v==*st.rbegin()){ // Indicates the maximum value of the current queue
if(a[i].id==k){ // just xm
printf("%d\n",c);
break;
}else st.erase(--st.end()),c++; // Delete the last element , That's the maximum
}else{ // Not the maximum , Simulation to the end of the team
a[n].v=a[i].v;
a[n++].id=a[i].id;
}
}
st.clear();
}
return 0;
}边栏推荐
- Complete linear regression manually based on pytoch framework
- Thinkcmf6.0 installation tutorial
- 电池、电机技术受到很大关注,反而电控技术却很少被提及?
- Register of assembly language by Wang Shuang
- Leetcode simple question: find the K beauty value of a number
- [step on the pit series] H5 cross domain problem of uniapp
- 【踩坑系列】uniapp之h5 跨域的问题
- JS cross browser parsing XML application
- Complex network modeling (III)
- 漏洞复现-easy_tornado
猜你喜欢

Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验

Bugku CTF daily one question chessboard with only black chess

【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)

快解析内网穿透为文档加密行业保驾护航

Content of string

拓维信息使用 Rainbond 的云原生落地实践

Yugu p1020 missile interception (binary search)

Interactive book delivery - signed version of Oracle DBA work notes

Réplication de vulnérabilité - désrialisation fastjson

快解析内网穿透助力外贸管理行业应对多种挑战
随机推荐
Codeforce c.strange test and acwing
Qinglong panel -- finishing usable scripts
[matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
Pytorch(六) —— 模型调优tricks
jeeSite 表单页面的Excel 导入功能
Complex network modeling (I)
Yugu p1020 missile interception (binary search)
buureservewp(2)
Recursive construction of maximum binary tree
Avatary's livedriver trial experience
运放电路的反馈电阻上并联一个电容是什么作用
Network learning (III) -- highly concurrent socket programming (epoll)
Linux server development, MySQL transaction principle analysis
Uniapp mobile terminal forced update function
Bugku CTF daily one question chessboard with only black chess
复杂网络建模(一)
2022 National latest fire-fighting facility operator (primary fire-fighting facility operator) simulation questions and answers
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Call pytorch API to complete linear regression
Complex network modeling (II)