ZJU-PAT 1057. Stack (30) 浙大2013年上机复试第三题

acm新手必备 浙大acm解答 代码库 zoj zju acm 新手必备 浙大 解答 代码库 zoj zju 立即下载
#pragma warning (disable:4786)
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

int n,d;;
int A[10005],B[10005];

int select(int num)
{
	for(int i=1;i<=d;i++) B[i]=A[i];
	sort(B+1,B+d+1);
	return B[num];
}

void process()
{
	char operate[1000];
	scanf("%s",operate);
	string s=operate;

	if(s=="Pop")
	{
		if(d==0)
			printf("Invalid\n");
		else 
		{
			printf("%d\n",A[d]);
			d--;
		}
	}
	else if(s=="PeekMedian")
	{
		if(d==0)
			printf("Invalid\n");
		else
		{
			int num;
			if(d%2==0) num=d/2;
			else
				num=(d+1)/2;
			printf("%d\n",select(num));
		}
	}
	else if(s=="Push")
	{
		int b;
		scanf("%d",&b);
		A[++d]=b;
	}
}

int main()
{
	//freopen("1.txt","r",stdin);
	while(scanf("%d",&n)!=EOF)
	{
		d=0;
		for(int i=0;i<n;i++) 
			process();
	}
	return 0;
}

利用树状数组+二分查找进行定位


#pragma warning (disable:4786)
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

const int N=100005;

int n,d;
int A[N],C[N];

int lowbit(int x)
{
    return x&(-x);
}

void update(int x,int num)
{
    while(x<=N)
    {
        C[x]+=num;
        x+=lowbit(x);
    }
}

int getsum(int x)
{
    int sum=0;
    while(x>0)
    {
        sum+=C[x];
        x-=lowbit(x);
    }
    return sum;
}

int select(int num)
{
    int L=0,R=N-1,M,ans;

    while(L<R-1)
    {
        M=(L+R)/2;
        ans=getsum(M);

        if(ans<num) L=M;
        else
            R=M;
    }
    return R;
}

void process()
{
    char operate[1000];
    scanf("%s",operate);
    string s=operate;

    if(s=="Pop")
    {
        if(d==0)
            printf("Invalid\n");
        else
        {
            printf("%d\n",A[d]);
            update(A[d],-1);
            d--;
        }
    }
    else if(s=="PeekMedian")
    {
        if(d==0)
            printf("Invalid\n");
        else
        {
            int num;
            if(d%2==0) num=d/2;
            else
                num=(d+1)/2;
            printf("%d\n",select(num));
        }
    }
    else if(s=="Push")
    {
        int b;
        scanf("%d",&b);
        update(b,1);
        A[++d]=b;
    }
}

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        d=0;
        for(int i=0; i<10005; i++) C[i]=0;
        for(int i=0; i<n; i++)
            process();
    }
    return 0;
}



HOPE:基于强化学习的混合策略路径规划器,适用于多样化停车场景 本文提出了一种混合策略路径规划器(HOPE),用于解决自动停车中的路径规划问题。HOPE结合了强化学习(RL)和Reeds-Shepp(RS)曲线,通过动作掩码机制引导RL智能体的探索,并利用Transformer融合环境感知信息与掩码。该方法在多样且复杂的停车场景中实现了超过97%的成功率,并通过真实实验验证了其泛化能力。此外,本文还提出了基于空间与障碍物分布的停车场景难度分级标准,进一步提升了训练与评估的效率。实验结果表明,HOPE在规划成功率和跨场景泛化能力上均优于传统的基于规则算法和朴素强化学习方法 阅读详情

相关推荐

IAR使用教程:如何导入现有工程并成功编译

详细介绍如何在IAR中导入现有工程项目并完成编译配置,解决常见报错问题。通过清晰的操作指引,帮助开发者快速上手iar使用教程中的关键环节,提升开发效率。

weixin_42437253的博客 883

ZJU-1094

<br /> 典型DP问题矩阵连乘顺序的逆问题。<br />给出矩阵尺寸和连乘的表达式,求用乘法的次数。<br /><br />从前往后不停的二合一,括号内可以视为一个矩阵,递归求解。<br />这道题的AC率好高,可能也有测试数据的功劳<br />//2008-01-12 16:35:10 Accepted 1094 C++ 00:00.00 432K #include<stdio.h> #include<string.h> struct matrix { int a,b; }; c

outer of the space 565

C# : 计算并输出这一天是这一年的第几天

C#之输入某年,然后输入某月,再输入某日,计算并输出这一天是这一年的第几天的功能算法

saitoDeng的博客 970

[水] ZOJ1094

stack模拟无视左括号,遇到字母就压栈,

woot forever woot 712

Tiff、jpg图片怎么样添加地理坐标信息

Tiff、jpg图片怎么样添加地理坐标信息 一般,外业调查只有地图资料,如专题图、或者地形图,如何把这些地图资料的扫描地图带上坐标信息,从而内业实现信息化处理?以上问题,可以解决,但根据不同情况有不同的处理方法。     第一种,上面有经纬度外框,图片是矩形,但是没有地理信息。 通过图框的两个角的坐标确定范围,分别是左上(140°E,30°N);右下(150°W,30°N) 解决方

树木_xzw的博客 2万+

保姆级教程:在阿里云ECS上用Docker一键部署EMQX MQTT服务器(Ubuntu 20.04)

本文提供在阿里云ECS上使用Docker一键部署EMQX MQTT服务器的详细教程,涵盖从实例创建、Docker环境配置到EMQX部署与优化的全流程。适合物联网开发者快速搭建高效、安全的MQTT消息服务器,适用于智能家居、工业物联网等场景。

weixin_28739079的博客 308

PAT (Advanced Level) Practise 1057 Stack (30)

1057. Stack (30) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Stack is one of the most fundamental data structures

wang_128的博客 432

VoIP概述

VoIP统一通信与VoIPVoIP与传统电话比较VoIP各项产品设备的类型及应用 统一通信与VoIP 统一通信指的是把计算机与传统通信技术统一成一体的新通信模式,融合计算机网络与传统通信网络在一个网络平台上,实现电话、传真、数据传输、音视频会议、呼叫中心、即时通信等众多应用服务 VoIP又称IP电话或IP网络电话,是Voice Over IP的缩写,这种技术通过对语音信号进行编码数字化,压缩处理成压缩帧,然后转换成为IP数据包在TCP/IP网络上进行传输,从而达到了在IP网络上进行语音通信目的 VoIP与传

kaminao的博客 4358

PAT真题练习(甲级)1057 Stack (30 分) (使用multiset和stack实现)

PAT真题练习(甲级)1057 Stack (30 分) 原题网址:https://pintia.cn/problem-sets/994805342720868352/problems/994805417945710592 Stack is one of the most fundamental data structures, which is based on the principle ...

Be Quick & Clever & Lucky 631

中国裁判文书网案例批量爬取

本文介绍了某法院网站数据采集的技术研究过程,主要包含JS逆向分析和数据解密方法。通过开发者工具分析发现页面数据经过加密处理,重点研究了ciphertext等加密参数的生成逻辑。文章详细记录了定位加密函数、扣取加密代码、解密数据处理的全流程,并验证了解密方法的有效性。研究过程中强调了技术使用的法律边界,明确声明仅用于合法技术研究,禁止任何非法数据爬取行为。最终实现了加密数据的成功解密,并解释了各请求参数的作用,为后续数据清洗和存储奠定了基础。

2303_80825459的博客 816

【WRF理论第十五期】WPS中输入geogrid二进制格式

WPS中输入geogrid二进制格式

WW、forever的博客 1079

ZJU-PAT 1057. Stack (30)---17有3组超时 浙大2013年上机复试第三题

题目: 很弱的代码: #include #include #include #include #include using namespace std; #define N 100000 int ans[N]; int tmp[N]; bool cmp(int a,int b){ return a<b; } int main() { int n,i,j,top,mid;

aialbert的专栏 707

YOLO11涨点优化:注意力魔改 | 新颖的多尺度卷积注意力(MSCA),即插即用,助力小目标检测

多尺度卷积注意力(MSCA),有效地提取上下文信息,新颖度高,创新十足。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 6316

PAT1057.Stack (30)

题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1057 这题为浙大2013年考研复试上机的最后一题,分数值为30分,大部分人开始都会出现有几个case超时的状况,可能源于频繁的在PeekMedian操作时进行排序,导致了超时。 利用树状数组,辅之以普通的二分法,可以在限定的100ms内得到结果。树状数组的介绍 //#include"

eli850934234的专栏 3211

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

PAT 1057 Stack

Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and Po...

weixin_30375427的博客 243

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

PAT 1057. Stack

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1057 题解: 维护一个小于等于mid的,一个大于mid的两部分,保持小的的大小和大的的大小一致或者比大的多一个,这样mid即小的的最后一个数。 代码: #include #include #include #include #include #include #include #inclu

Ted's 游乐园 2908

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

PAT-1057 Stack (树状数组 + 二分查找)

1057. Stack Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto t

Phyloser的博客 648

1057 Stack (30 分)

1057 Stack (30 分) Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the t...

A_Bo的博客 732

PAT 1057. Stack (30)

1057. Stack (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Stack is one of the most fundamental data structures

FrozenShore 660

1057

# include main() { int n,i,x=2,sum=2; scanf("%d",&n); for(i=1;i<n;i++) { x=x+3; sum=sum+x; } printf("%d",sum); }

张松超的博客 417

1057 Stack (30 分)PAT (Advanced Level) Practice

Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and Po...

mlm5678的博客 229

1057. Stack (30)-PAT甲级真题(树状数组)

1057. Stack (30) Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the to

柳婼 の blog 4637

PAT1057 Stack (30)(树状数组)

题意: 模拟一个栈,要求可以输出中位数。 思路: 这题还是有点意思,看题意就知道会卡时间复杂度,想着用multiset试一下发现果然有几个点过不去,后面就没想出来。实际这题应该用树状数组做: Push x:就update(x,1),就是树状数组的区间更新,c[i]+=1,说明值为i的数出现并更新与其相关的数 Pop:就update(x,-1),c[i]-=1,将值为i的数以及和它相关的数...

SeasonJoe的博客 535

1057 Stack

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805417945710592 题目描述比较简单,在栈的操作基础上新增一个取中值的操作 思路也很直接,直接用栈进行模拟,果然,时间爆掉了,代码如下: #include&amp;amp;lt;iostream&amp;amp;gt; #include&amp;amp;lt;stack&amp;amp;gt; #include...

huhusw_的博客 669

1057 Stack (multiset&维护中位数)

1057Stack(30分) Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the t...

lannister_awalys_pay的博客 468

LintCode 解题记录17.5.10(tag:线段树)

第一次学习“线段树”这种数据结构。记录一下LintCode线段树相关的题目。LintCode 201 线段树的构造 每个节点代表一个[start, end]的间隔(interval),同时还可以用第三变量val来存储和具有区间和性质的变量(比如该区间的最大值、最小值、元素和、元素个数等等)。具有区间和的意思就是说在一个区间上的操作是否可以转化为两个子区间上的操作。 父亲节点的间隔为[start,

每天完成一个小目标 453
上一篇: ZJU-PAT 1055. The World's Richest (25) 浙大2013年上机复试第二题
下一篇: ZJU-PAT 1056. Mice and Rice (25) 浙大2013年上机复试第四题
Matrix_Reloaded
博客等级 码龄14年 18粉丝 36原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值