hdu3410 Passing the Message

2024-05-11 23:48
文章标签 message passing hdu3410

本文主要是介绍hdu3410 Passing the Message,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目链接:hdu3410
题目大意:
T组数据
输入n个人的身高(n<=50000),身高各不相同.
输出每个人左右各比他矮的人中最高的那个.

题解:
单调队列
从左往右从右往左各一次

如果hyc来了别看…
我在刷水题qwq我好菜啊.jpg

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 51000int mymin(int x,int y) {return (x<y)?x:y;}
int mymax(int x,int y) {return (x>y)?x:y;}
int a[maxn],l[maxn],r[maxn],q[maxn],cnt;
int main()
{int T,i,n,tp;scanf("%d",&T);for (int ca=1;ca<=T;ca++){scanf("%d",&n);for (i=1;i<=n;i++){scanf("%d",&a[i]);l[i]=r[i]=q[i]=0;}tp=0;for (i=1;i<=n;i++){while (tp>0 && a[i]>a[q[tp]]) {l[i]=(a[l[i]]>a[q[tp]])?l[i]:q[tp];tp--;}q[++tp]=i;}tp=0;for (i=n;i>=1;i--){while (tp>0 && a[i]>a[q[tp]]) {r[i]=(a[r[i]]>a[q[tp]])?r[i]:q[tp];tp--;}q[++tp]=i;}printf("Case %d:\n",ca);for (i=1;i<=n;i++)printf("%d %d\n",l[i],r[i]);}return 0;
}

这篇关于hdu3410 Passing the Message的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/981007

相关文章

SDUT1500_Message Flood(字典树)

Message Flood Time Limit: 1500MS Memory limit: 65536K 题目描述 Well, how do you feel about mobile phone? Your answer would probably be something like that "It's so convenient and benefits peop

MQTT: Will Message

Will Message (遗嘱信息) Will 消息需要被服务器保存在服务器端,和当前网络连接关联。 Will 消息必须在后续网络连接断开之后被分发出去(Publish), 除非服务器收到了来自客户端的 Disconnect 包。 发布 Will信息的情形包括但不限于: 服务器检测到客户端连接中断或者 I/O 错误。客户端没有按照约定的 Keep-Alive 时间发送 Ping 消息。客

Android源码解析Handler系列第(一)篇 --- Message全局池

1、UI不能在子线程中更新是个伪命题 我们常说UI需要在主线程中进行更新,子线程就不能更新UI吗?不是,我们并不是说不能在子线程中更新UI,而是说UI必须要在它的创建线程中进行更新,比如下面一段代码在子线程更新UI就不会报错。 new Thread(new Runnable() {@Overridepublic void run() {TextView textView=new

Hive 2.3.0 MetaException(message:Version information not found in metastore. )

使用Hive 2.3.0 配置远程模式(Remote)时,执行hive --service metastore命令时出现MetaException(message:Version information not found in metastore. )错误。 解决办法: The necessary tables required for the metastore are missing i

Message Queue-消息队列

简述 在计算机科学中,消息队列(Message Queue,MQ)是一种进程间通信或者同一进程的不同线程间的通信方式。MQ允许应用程序间通过发送消息来进行通信,当目标程序繁忙或者掉线,来不及处理消息,MQ会提供暂时的消息存储。 MQ中有两个关键字: 消息:发送方与接收方之间传递的数据,其实际上就是一些带有头信息的字节数组。队列:一种数据结构,按照消息发送的时间顺序排列,先

从python应用app向微软Microsoft Teams Channel发送消息message

一、简介 有这样的需求,web app需要提供功能可以发送消息到Teams来提醒用户。所以需要将发消息到Teams功能集成到web app中。由于我们的web app是python开发的,所以使用pyteams库。 先看效果:有标题、内容、链接、@用户 二、步骤 2.1 首先在Teams channel中建一个webhook 直接参考官方文档:Create an Incoming

Handler Message总结

当应用程序启动时,会开启一个主线程(也就是UI线程),由她来管理UI,监听用户点击,来响应用户并分发事件等。所以一般在主线程中不要执行比较耗时的操作,如联网下载数据等,否则出现ANR错误。所以就将这些操作放在子线程中,但是由于AndroidUI线程是不安全的,所以只能在主线程中更新UI。Handler就是用来 子线程和创建Handler的线程进行通信的。          Handl

Message Flood(字典树)

题目描述 Well, how do you feel about mobile phone? Your answer would probably be something like that "It's so convenient and benefits people a lot". However, If you ask Merlin this question on the New Y

22 Message 组件

Tkinter Message 组件使用指南 Tkinter 的 Message 组件用于显示多行文本消息。它通常用于显示提示信息、警告或状态更新。Message 组件能够自动换行,以适应其分配的空间。以下是对 Message 组件的详细说明和一个使用案例。 Message 组件属性 text: 要显示的文本消息。width: 指定组件的宽度,可以是像素值或字符数。height: 指定组件的

Azure OpenAI citations with message correlation

题意:“Azure OpenAI 引用与消息关联” 问题背景: I am trying out Azure OpenAI with my own data. The data is uploaded to Azure Blob Storage and indexed for use with Azure AI search “我正在尝试使用自己的数据进行 Azure OpenAI。数