当前位置:网站首页>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;
}边栏推荐
- Unityhub cracking & unity cracking
- Qinglong panel - today's headlines
- 复杂网络建模(三)
- Bugku CTF daily one question chessboard with only black chess
- 数据库实时同步利器——CDC(变化数据捕获技术)
- It took "7" years to build the robot framework into a micro service
- JS cross browser parsing XML application
- CDC (change data capture technology), a powerful tool for real-time database synchronization
- [matlab] when matrix multiplication in Simulink user-defined function does not work properly, matrix multiplication module in module library can be used instead
- The element with setfieldsvalue set is obtained as undefined with GetFieldValue
猜你喜欢

运放电路的反馈电阻上并联一个电容是什么作用

Vulnerability recurrence fastjson deserialization

Yugu p1020 missile interception (binary search)

Avatary的LiveDriver试用体验

Rainbond 5.7.1 支持对接多家公有云和集群异常报警

The zblog plug-in supports the plug-in pushed by Baidu Sogou 360

Li Kou interview question 04.01 Path between nodes

【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
![[quickstart to Digital IC Validation] 15. Basic syntax for SystemVerilog Learning 2 (operator, type conversion, loop, Task / Function... Including practical exercises)](/img/e1/9a047ef13299b94b5314ee6865ba26.png)
[quickstart to Digital IC Validation] 15. Basic syntax for SystemVerilog Learning 2 (operator, type conversion, loop, Task / Function... Including practical exercises)

Niu Mei's mathematical problem --- combinatorial number
随机推荐
Avatary's livedriver trial experience
快解析内网穿透助力外贸管理行业应对多种挑战
Force buckle 144 Preorder traversal of binary tree
Summary of redis functions
Jmeter 的使用
Hisense TV starts the developer mode
Merging binary trees by recursion
Li Kou interview question 04.01 Path between nodes
【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
Register of assembly language by Wang Shuang
Content of string
基于Pytorch 框架手动完成线性回归
Quickly use Jacobo code coverage statistics
C language queue
Notes on PHP penetration test topics
调用 pytorch API完成线性回归
DNS server configuration
运放电路的反馈电阻上并联一个电容是什么作用
Minimum absolute difference of binary search tree (use medium order traversal as an ordered array)
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number