PAT甲级1028,1029解题报告

libjpeg-turbo图片解码 VS opencv 本文对比了libjpeg-turbo和opencv在图像解码层面的耗时情况,及解码数据是否存在diff 阅读详情

 

1028:

1028 List Sorting (25 分)

Excel can sort records according to any column. Now you are supposed to imitate this function.

Input Specification:

Each input file contains one test case. For each case, the first line contains two integers N (≤10​5​​) and C, where N is the number of records and C is the column that you are supposed to sort the records with. Then Nlines follow, each contains a record of a student. A student's record consists of his or her distinct ID (a 6-digit number), name (a string with no more than 8 characters without space), and grade (an integer between 0 and 100, inclusive).

Output Specification:

For each test case, output the sorting result in N lines. That is, if C = 1 then the records must be sorted in increasing order according to ID's; if C = 2 then the records must be sorted in non-decreasing order according to names; and if C = 3 then the records must be sorted in non-decreasing order according to grades. If there are several students who have the same name or grade, they must be sorted according to their ID's in increasing order.

Sample Input 1:

3 1
000007 James 85
000010 Amy 90
000001 Zoe 60

Sample Output 1:

000001 Zoe 60
000007 James 85
000010 Amy 90

Sample Input 2:

4 2
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 98

Sample Output 2:

000010 Amy 90
000002 James 98
000007 James 85
000001 Zoe 60

Sample Input 3:

4 3
000007 James 85
000010 Amy 90
000001 Zoe 60
000002 James 90

Sample Output 3:

000001 Zoe 60
000007 James 85
000002 James 90
000010 Amy 90

题目大意:输入总人数和tag,然后每个人的学号,姓名,成绩,要求按照tag的不同用不同方式排序得出排序结果。

解题思路:水题,排序排一下输出一下。

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<map>
using namespace std;
struct stu {
	string id;
	string name;
	int grade;
};
bool Cmp1(stu a,stu b){
	return a.id < b.id;
}
bool Cmp2(stu a, stu b) {
	if (a.name < b.name)return true;
	else if (a.name == b.name)return a.id < b.id;
	else return false;
}
bool Cmp3(stu a, stu b) {
	if (a.grade < b.grade)return true;
	else if (a.grade == b.grade)return a.id < b.id;
	else
		return false;
}
vector<stu> cur;
int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		stu tmp;
		cin >> tmp.id >> tmp.name >> tmp.grade;
		cur.push_back(tmp);
	}
	if (k == 1) {
		sort(cur.begin(), cur.end(), Cmp1);
	}
	else if (k == 2) {
		sort(cur.begin(), cur.end(), Cmp2);
	}
	else {
		sort(cur.begin(), cur.end(), Cmp3);
	}
	for (int i = 0; i < cur.size(); i++) {
		cout << cur[i].id << " " << cur[i].name << " " << cur[i].grade << endl;
	}
	return 0;
}

1029:

1029 Median (25 分)

Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is 15. The median of two sequences is defined to be the median of the nondecreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.

Given two increasing sequences of integers, you are asked to find their median.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (≤2×10​5​​) is the size of that sequence. Then N integers follow, separated by a space. It is guaranteed that all the integers are in the range of long int.

Output Specification:

For each test case you should output the median of the two given sequences in a line.

Sample Input:

4 11 12 13 14
5 9 10 15 16 17

Sample Output:

13

题目大意:给两串序列(n<=2e5),输出两串序列之间的中序数,每个数据不超出long int。

解题思路:在参考他人博客之前,没做对过,最高16.思路历程:

1.第一眼看到,没管直接STL里面list,因为很像数据结构基础题两个有序链表的合并,16分,gg。内存超出限制。

2.然后发现了题目的long int,第一眼的时候认为long int一定是4位的,因为感觉现代的个人PC,long int 和int是一样的,都是四位,然后是4*4e5的极端情况最后是应该不会超出1.5MB。

3.后来用类似注入的方法。。故意制造死循环。发现PAT系统的机器long int是8位的。。那肯定是超出限制了。也就是暗示我们在数据量极大的情况下,不能把两个数组全部读完。

4.然后一筹莫展的情况下,去参考了他人的题解,大多数的题解都是错误的。直到看到一个考虑到内存因素的。

5.看到用队列维护就有想法了,思路其实很简单,把第一个数组a读完,并在最后设置一个哨兵。不需要用long int存。long int怎么样都是超时的,把long int当成int处理就是了。哨兵为了方便,直接赋值最大的int。可以确定中序数是res=(n1+n2)%2!=0?(n1+n2)/2+1:(n1+n2)/2个;

6.然后维护队列,再读第二个数组b的时候,每读一个,把a,b中小的那个队头pop出去,直到要push第res个时候,把最终的结果输出。

7.考虑到可能是第二个数组比较短。所以要设置一个标志,如果还没有找到这个res结果,那么就继续累加,不断pop出a,b中的表头最小者直到输出。

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<map>
#include<list>
#include<climits>
#include<queue>
using namespace std;
queue<int> a, b;
int main()
{
	int n1,n2;
	cin >> n1;
	for (int i = 0; i < n1; i++) {
		int num;
		cin >> num;
		a.push(num);
	}
	a.push(INT_MAX);
	cin >> n2;
	int index=0;
	int res = (n1 + n2) % 2 != 0 ? (n1 + n2) / 2 : (n1 + n2) / 2 - 1;
	int ans;
	bool flag = false;
	for (int i = 0; i < n2; i++) {
		int num;
		cin >> num;
		b.push(num);
		if (index == res) {
			ans=min(a.front(), b.front());
			flag = true;
			break;
		}
		if (a.front() < b.front())
			a.pop();
		else
			b.pop();
		index++;
	}
	if (flag) {
		cout << ans << endl;
	}
	else {
		b.push(INT_MAX);
		for (; index < res; index++) {
			if (a.front() < b.front())
				a.pop();
			else
				b.pop();
		}

		cout << min(a.front(), b.front()) << endl;
	}
	return 0;
}

题目的那个long int是真的坑。。

编织数据的实时脉络——构建基于MySQL的数据编织平台,实现实时数据治理 除了上述基本设置外,我们还可以根据实际应用场景自定义一些特定的监控项目。例如,对于某些高并发读写的表,可能需要特别关注它们的锁等待时间和回滚段使用率;而对于涉及到跨库关联查询的操作,则应当着重检查网络延迟及缓存命中率等因素。-- 获取InnoDB行级锁等待情况-- 统计各表的缓存命中率这段SQL脚本不仅展示了如何查询InnoDB引擎下的锁争用状况,还介绍了计算表级别缓存命中率的方法,有助于深入理解系统的运行状态。 阅读详情

相关推荐

Spring Boot 实现多图片上传并回显,涨姿势了~

上传 Controller的代码非常简单,由于用了SpringMVC框架,所以直接用MultipartFile来接即可。由于是多图片上传所以用数组来接。此处应该注意参数名应该和<input>中的name值相对应: @RequestMapping("/pic") @ResponseBody publicResponseEntity<String>pic(MultipartFile[]pictures)throwsException{ ResponseEnti...

weixin_54556126的博客 904

1028 List Sorting (25分)【结构体排序】

1028List Sorting(25分) Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, th...

胡小涛的博客 202

光谱特征选择之模拟退火算法SA

光谱特征选择之模拟退火算法SA。

weixin_42621095的博客 906

PAT甲级 1029median 参考柳神解题思路

先扔完整代码,可通过在线测试,具体迟点再写 #include&lt;iostream&gt; #include&lt;vector&gt; using namespace std; int main() { int m, n; cin &gt;&gt; m; vector&lt;int&gt; arr1(m); for (int i = 0; i &lt; m; i++) { c...

lzy我就来随便逛逛的博客 3309

【Q1/论文复现】:利用 CHARLS 数据库考察抗高血压药物依从性和认知衰退

摘要: 北京大学团队基于CHARLS数据(2011-2018)的纵向研究发现,抗高血压药物高依从性能显著延缓中国45岁及以上社区中老年人的认知衰退。研究表明,坚持服药者7年内全局认知衰退速度降低0.014SD/年,记忆功能衰退减缓0.023SD/年,效果接近正常血压人群水平。研究还提示社会经济地位(SES)可能通过影响用药依从性间接调控认知衰老进程。该成果为高血压管理对认知保护提供了人群级证据,发表于《BMC Medicine》(DOI:10.1186/s12916-025-03949-8)。

dingdianbangni的博客 814

MATLAB 2022b 用户专属:保姆级IPOPT求解器安装配置全流程(含OPTI工具箱)

本文为MATLAB 2022b用户提供IPOPT求解器的详细安装与配置指南,涵盖OPTI工具箱的适配安装、环境变量设置及常见问题解决方案。通过实战案例演示非线性优化问题的求解过程,帮助用户高效部署这一强大的优化工具,提升工程计算效率。

weixin_29092031的博客 413

PAT 甲级 1029 JAVA

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.i

Zaaztt的博客 232

2026年德明利数字IC笔试试卷带答案

摘要 本次笔试涵盖数字IC设计、存储控制器及NAND Flash相关核心知识,总分100分,时长90分钟。试题分为四部分: 单选题(30分):涉及多通道架构(提升并行带宽)、时序约束(建立/保持时间)、逻辑化简、跨时钟域格雷码应用、FTL垃圾回收(空间回收)等; 波形分析(15分):考察D触发器行为、分频电路、亚稳态成因及同步器延迟特性; 多选题(25分):聚焦亚稳态处理、异步FIFO设计(格雷码指针)、NAND控制器关键技术(多通道/DMA/ECC)及FW/HW协同机制; 简答题(20分):解析建立/保持

Open 98

pat 甲级 1029 Median

在pat没修改的时候好像sort或者nth_element 可以过 现在加了内存限制,好多代码都不行了 这个是第一版(不加内存限制好简单啊); 学习一下nth_element (a,b,c); 在&amp;lt;algortithm&amp;gt;里 #include &amp;lt;cstdio&amp;gt; #include &amp;lt;iostream&amp;gt; #include &amp;lt;algorithm&

咸鱼之井的博客 311

企业第三方应用开发概述_测试第三方应用对接企业_以及如何使用流程_Demo演示---企业微信开发002

那么第三方公司开发了应用,做为服务提供商,如果,一个企业想使用这个应用,我开发的这个应用的话,那么。其实就是给我们的应用,安装一个,使用他的企业,分配一共企业 允许这个企业使用我们的应用的功能,可以看到其实就是多了运营规范,因为,第三方应用,其实就相当于,是第三方公司开发的,程序,首先来看一下。然后再来看,这里我们选择这个公司,其实可以,选择到具体的,部门,或者是。然后我们使用一个企业的管理员账号进行,扫码,来授权,这个应用,可以。其实就是指定,我这个企业中,哪个部门,或者哪些员工,可以使用。

添柴程序猿的专栏 429

MuJoCo 入门教程(二)

本章介绍 MuJoCo 的数学和算法基础。对于熟悉广义或关节坐标建模和仿真的读者来说,整体框架是相当标准的。因此,我们将对这些材料进行简要总结。本章的大部分篇幅用于介绍我们如何处理接触和其他约束条件。这种方法是基于我们最近的研究,也是 MuJoCo 所独有的,因此我们花时间对其进行了详细的激励和解释。更多信息可参见下面的论文,尽管本章中的一些技术思想是新的,在其他地方还没有描述过。

机器人控制与仿真应用 3723

1029. Median (25)

时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given an increasing sequence S of N integers, themedianis the number at the middle position. Fo...

weixin_30367543的博客 188

BME688传感器原理图设计,已量产(环境传感器)

在便携式空气质量监测、可穿戴健康设备这类低功耗场景中,BME688 这类集成了 VOC、温湿度、气压的四合一 MEMS 传感器越来越受欢迎 —— 它体积小、功耗低,刚好匹配便携设备的需求。但这类小信号传感器对电源噪声、电平匹配的要求很细,今天结合实际项目里的一款 BME688 接口电路,聊聊硬件设计的关键细节。

不脱发的程序猿 529

[PAT甲级]1029. 取中位数

PAT甲级真题1029,有点小坑的排序题

hzykirito的博客 266

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

PAT甲级JAVA题解汇总

github地址:https://github.com/zzzmj/pat-java

zmjのblog 1556

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

PAT (Basic Level) 1029 旧键盘 (20分)JAVA解法

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。 输入格式: 输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 _(代表空格)组成。题目保证 2 个字符串均非空。 输出格式: 按照发现顺序,在一行中输...

qq_44028719的博客 347

InTheHand.Net.Personal+BlueTooth4,蓝牙开发

项目中有蓝牙开发的必备dll,现在网上相关的文档博客不少,有的说的多有的说少,但是却很少有这两个dll,分享一下。

PAT_B_1029_Java(20分)

toUpperCase() 用于把字符串转换为大写 Set.add() 向 Set 集合添加对象 Set.contains() 判断 Set 集合是否包含指定的对象 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Set; public class Main...

TYPFOON的博客 213

PAT 甲级 1029 Median (25分)

Note 双指针 注意程序中的index++!!若是按照index++,则可能出现,index=3,target=4,index!=target 不会break;但是继续执行index++后,index=target,那么就会影响到退出while后的if-else!!所以改为**++index**,相应的target也要+1。 Code: #include<bits/stdc++.h> using namespace std; int main(){ #ifndef ONLINE_JUD

HHCCCaptain的博客 195

PAT 甲级A1029 测试点3 6 未通过解决办法

若采用先计算位置,count计数直到所求位置的方法(two_point法)且出现测试点3 6 未通过,建议尝试以下测试用例。 input: 3 1 2 3 9 4 5 6 7 8 9 10 11 12 正确的output应该为: 6 若输出错误,很有可能是因为比较过程中,一个数组已经走到了尽头,这时,在数组末尾保存一个无限大的数,就可以解决此类问题,代码如下: #include...

国家熬夜运动比赛中心 808

PAT 甲级 1049 JAVA

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.i

Zaaztt的博客 193

PAT 1028 List Sorting (25分)

题目: Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, the first line contains t...

qq_42593220的博客 194

pta--1028 List Sorting(25 分)(sort cmp重写)

1028 List Sorting(25 分) Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, th...

来啦(#^.^#) 583

A1028

题目 1028 List Sorting (25point(s)) Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, the first line contains two integers N (≤10​5​​) an

weixin_45070743的博客 164

PAT (Advanced Level) 1028 List Sorting (25 分)

1028List Sorting(25分) Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contain...

就当一次路过丶的沙滩 264

【PAT(甲级)】1028 List Sorting(有易错的测试点分析)

【PAT(甲级)】1028 List Sorting 有详细的解题思路和测试点,内附详细注释的代码

weixin_55202895的博客 422

PAT甲级 1029 Median(25) (STL)

PAT甲级 1029 Median(25) (STL)

NHS6671的博客 213
上一篇: 如何获取百度云下载直链
下一篇: PAT甲级1031,1032解题报告
Tate_Brown
博客等级 码龄9年 39粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址