当前位置:网站首页>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;
}
边栏推荐
- jeeSite 表单页面的Excel 导入功能
- Hisense TV starts the developer mode
- Minimum absolute difference of binary search tree (use medium order traversal as an ordered array)
- 使用 Nocalhost 开发 Rainbond 上的微服务应用
- Record a stroke skin bone error of the skirt
- 通俗易懂单点登录SSO
- [quick start of Digital IC Verification] 15. Basic syntax of SystemVerilog learning 2 (operators, type conversion, loops, task/function... Including practical exercises)
- Linux server development, MySQL cache strategy
- ROS Bridge 笔记(05)— carla_ackermann_control 功能包(将Ackermann messages 转化为 CarlaEgoVehicleControl 消息)
- Téléchargement des données de conception des puces
猜你喜欢
QT learning 26 integrated example of layout management
Jmeter 的使用
Game attack and defense world reverse
藏书馆App基于Rainbond实现云原生DevOps的实践
LeetCode简单题之字符串中最大的 3 位相同数字
Fast parsing intranet penetration escorts the document encryption industry
Interactive book delivery - signed version of Oracle DBA work notes
【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
CTF-WEB shrine模板注入nmap的基本使用
JS quick start (I)
随机推荐
船载雷达天线滑环的使用
调用 pytorch API完成线性回归
Quick analysis of Intranet penetration helps the foreign trade management industry cope with a variety of challenges
Topic not received? Try this
JS quick start (I)
漏洞复现-easy_tornado
C language queue
Force buckle 144 Preorder traversal of binary tree
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
在 Rainbond 中一键安装高可用 Nacos 集群
OpenJudge NOI 2.1 1752:鸡兔同笼
Dedecms collects content without writing rules
JSON data flattening pd json_ normalize
Basic use of CTF web shrink template injection nmap
Use of JMeter
Zsh shell adds automatic completion and syntax highlighting
Linux Installation MySQL 8.0 configuration
Network learning (I) -- basic model learning
OpenVSCode云端IDE加入Rainbond一体化开发体系
buureservewp(2)