- 博客(45)
- 收藏
- 关注
转载 【PAT】【贪心线性】1033 To Fill or Not to Fill (25 分)
题目链接:1033 To Fill or Not to Fill (25 分)With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may .
2021-07-10 22:16:05
161
原创 【PAT】【链表遍历】1032 Sharing (25 分)
题目链接:1032 Sharing (25 分)To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example,loadingandbeingare stored...
2021-07-05 12:15:24
167
原创 【PAT】【spfa + dfs】1030 Travel Plan (30 分)
题目链接:1030 Travel Plan (30 分)A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting c.
2021-07-03 11:47:08
261
原创 【PAT】【合并两有序序列+找中位数】1029 Median (25 分)
题目链接: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 sequenc.
2021-07-01 21:57:41
103
原创 【PAT】【水题排序】1028 List Sorting (25 分)
题目链接: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 integersN(≤105) an...
2021-06-30 19:59:50
96
原创 [PAT] [繁琐排队模拟] 1026 Table Tennis (30 分)
题目链接:1026 Table Tennis (30 分)A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open when they arrive, they will be assigned to the available table with the sm.
2021-06-28 22:21:25
151
原创 【PAT】【进制】1027 Colors in Mars (20 分)
题目链接:1027 Colors in Mars (20 分)People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are forRed, the middle 2 digits forGreen, and the...
2021-06-26 20:11:49
78
原创 【PAT】【简单模拟排序】1025 PAT Ranking (25 分)
题目链接:1025 PAT Ranking (25 分)Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately.
2021-06-25 17:36:14
356
原创 【PAT】【大整数加法+字符串方式实现】1024 Palindromic Number (25 分)
题目链接:1024 Palindromic Number (25 分)A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.Non-palindromic..
2021-06-24 16:47:38
193
原创 【PAT】【简单大整数运算】1023 Have Fun with Numbers (20 分)
题目链接:1023 Have Fun with Numbers (20 分)Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly.
2021-06-23 17:04:01
77
原创 【PAT】【字符串处理 + 简单映射】1022 Digital Library (30 分)
// 字符串处理题以及简单映射// 解题思路:// 可以发现,其实书的相关信息都是string,甚至id号也可以这么看// 而且要求是给出其中一个信息进行查询相应的id号,那么简单的用一个string 到 set的映射就可以了// 用set主要是为了可以按升序输出,然后按题目要求保存和查询就可以了// 这里的set<int> 是因为我觉得int 会比 string节省开销,但却造就我疏忽了一个问题// 注意点:// 上面说的,也就是测试点3、4的坑点,id号首部可能有零,int.
2021-06-18 11:43:20
121
原创 【PAT】【树直径 + 连通分量】1021 Deepest Root (25 分)
// 解题思路:// 其实就是遍历得到树直径 混合 连通分量的个数// 进行两次dfs// 第一次:// 只需要任选一个节点作为根节点开始遍历,得到深度最大的一个或多个节点// 第二次:// 再从这其中任选一个,再作为根节点遍历得到深度最大的节点 即是另一端// !需要注意的是,要进行去重,可能会在这两次中得到了相同的节点,这里用set保存 以去重// pat的测试数据真是 把我这些思路总是不够全面的家伙 虐的够惨,处处是坑点啊#include <iostream>..
2021-06-17 11:26:52
109
原创 【PAT】【树的已知二序求具体树问题】1020 Tree Traversals (25 分)
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.Input Specification:Each ...
2021-06-16 15:06:59
80
原创 【PAT】【简单进制转换】1019 General Palindromic Number (20 分)
#include <iostream>#include <cstdio>#include <vector>using namespace std;#define ll long long// 解题思路:// 简单进行进制转换,遍历一遍判断是否回文,按要求输出结果即可vector<int> ans;bool fun(int n, int b){ // 进制转换,用vector保存 vector<int> t;..
2021-06-16 12:49:51
87
原创 【PAT】【dijkstra + dfs】1018 Public Bike Management (30 分)
#include <iostream>#include <cstdio>#include <vector>#include <queue>#include <cstring>using namespace std;struct edge{ int v, w;};struct node{ int id, d; bool operator<(const node &r) const .
2021-06-15 22:24:51
86
原创 【PAT】【银行排队繁琐模拟】1017 Queueing at Bank
Suppose a bank hasKwindows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there ...
2021-06-11 16:37:13
167
1
原创 【PAT】【繁琐模拟】1016 Phone Bills (25 分)
题目链接:1016 Phone Bills A long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a.
2021-06-10 13:11:34
87
原创 【洛谷】【区间与环形dp】P1880 [NOI1995] 石子合并
题目描述在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分。试设计出一个算法,计算出将N堆石子合并成1堆的最小得分和最大得分。输入格式数据的第1行是正整数N,表示有N堆石子。第2行有N个整数,第i个整数ai表示第i堆石子的个数。输出格式输出共2行,第1行为最小得分,第2行为最大得分。输入输出样例输入 #1复制44 5...
2021-06-02 18:50:04
142
原创 【洛谷】【模板】P3371 和 P4779 单源最短路径
题目链接:P4779 【模板】单源最短路径(标准版)P3371 【模板】单源最短路径(弱化版)dijkstra最短路模板 :#include <iostream>#include <cstdio>#include <cstring>#include <queue>using namespace std;inline int read(){ register int x = 0, f = 1; re...
2021-05-30 15:07:17
104
原创 【洛谷】【dp最长上升和下降子序列组成的最长序列】P1091 [NOIP2004 提高组] 合唱队形
题目描述NN位同学站成一排,音乐老师要请其中的(N-KN−K)位同学出列,使得剩下的KK位同学排成合唱队形。合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1,2,…,K1,2,…,K,他们的身高分别为T_1,T_2,…,T_KT1,T2,…,TK, 则他们的身高满足T_1<...<T_i>T_{i+1}>…>T_K(1 \le i \le K)T1<...<Ti>Ti+1>…>TK(1≤i≤K)。你的任务是,已.
2021-05-28 21:46:24
156
原创 【洛谷】【dp】【要求两单调性,转成求最长上升子序列】P1233 木棍加工
题目描述一堆木头棍子共有n根,每根棍子的长度和宽度都是已知的。棍子可以被一台机器一个接一个地加工。机器处理一根棍子之前需要准备时间。准备时间是这样定义的:第一根棍子的准备时间为1分钟;如果刚处理完长度为L,宽度为W的棍子,那么如果下一个棍子长度为Li,宽度为Wi,并且满足L>=Li,W>=Wi,这个棍子就不需要准备时间,否则需要1分钟的准备时间;计算处理完n根棍子所需要的最短准备时间。比如,你有5根棍子,长度和宽度分别为(4, 9),(5, 2),(2, 1),(3, 5),(.
2021-05-27 13:35:45
100
原创 【洛谷】【线性dp,类01背包】P1077 摆花
题目描述小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共mm盆。通过调查顾客的喜好,小明列出了顾客最喜欢的nn种花,从11到nn标号。为了在门口展出更多种花,规定第ii种花不能超过a_iai盆,摆花时同一种花放在一起,且不同种类的花需按标号的从小到大的顺序依次摆列。试编程计算,一共有多少种不同的摆花方案。输入格式第一行包含两个正整数nn和mm,中间用一个空格隔开。第二行有nn个整数,每两个整数之间用一个空格隔开,依次表示a_1,a_2,…,a_na1,a2,…,an.
2021-05-26 21:35:48
136
原创 【洛谷】【线性dp】P2758 编辑距离
题目描述设A和B是两个字符串。我们要用最少的字符操作次数,将字符串A转换为字符串B。这里所说的字符操作共有三种:1、删除一个字符;2、插入一个字符;3、将一个字符改为另一个字符;!皆为小写字母!输入格式第一行为字符串A;第二行为字符串B;字符串A和B的长度均小于2000。输出格式只有一个正整数,为最少字符操作次数。输入输出样例输入 #1复制sfdqxbwgfdgw输出 #1复制4#include <iostream>#.
2021-05-26 19:35:49
202
原创 【洛谷】【最长递增子序列O(nlog2n)】P1020 导弹拦截[NOIP1999 普及组]
题目链接:https://www.luogu.com.cn/problem/P1020题目描述某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭。由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹。输入导弹依次飞来的高度(雷达给出的高度数据是≤50000的正整数),计算这套系统最多能拦截多少导弹,如果要拦截所有导弹最少要配备多少套..
2021-05-22 13:06:40
186
原创 【洛谷】【最大公共子序列】P1439 【模板】最长公共子序列
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;//解题思路://解法二O(nlog2n)://由于两串值都一样,将一个串离散化成升序1-n//则在读入另一串时,按照离散化顺序后的最长递增序列则是最大公共子串#define max(x, y) (x) > (y)? (x) : (y);inline void read(int &x).
2021-05-20 23:26:26
295
原创 【洛谷】【dp】P1434 [SHOI2002]滑雪
题目描述Michael 喜欢滑雪。这并不奇怪,因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael 想知道在一个区域中最长的滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子:1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9一个人可以从某个点滑向上下左右相...
2021-05-19 15:58:45
167
原创 【PAT】【字符串和进制转换】1015 Reversible Primes
1015 Reversible Primes (20 分)Areversible primein any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.Now given any t...
2021-05-19 12:15:48
49
原创 【PAT】【模拟】1014 Waiting in Line
1014 Waiting in Line (30 分)Suppose a bank hasNwindows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:The space inside the yellow line in...
2021-05-18 15:08:19
74
原创 【PAT】【割点】1013 Battle Over Cities
1013 Battle Over Cities (25 分)It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any othe...
2021-05-18 11:52:06
131
原创 【PAT】【排序】1012 The Best Rank
#include <iostream>#include <cstdio>#include <algorithm>#include <map>#include <set>#include <cmath>using namespace std;//总结:做题思路要清晰,不能急,不然可能反而走弯路更慢//第一种解法是自己写的都看不下去的傻瓜(智障)式做法//开四个结构体数组,每个数组定义一个排序方式cmpa,排好序后将排.
2021-05-16 16:17:05
69
原创 【PAT】[简单模拟] 1011 World Cup Betting
#include <iostream>#include <cstdio>#include <iomanip>using namespace std;//简单模拟题//唯一的难点是英语题意。。。//odd - 赔率;trophy - 奖杯int main(){ double res(1), a, b, c, t; for(int i = 1; i <= 3; i++) { scanf("%lf %lf %l.
2021-05-15 14:11:41
66
原创 【PAT】【二分】【进制转换】1010 Radix
#include <iostream>#include <cstdio>using namespace std;//这道题不难,但是坑点真的是非常多,花了非常多的时间才把全部测试点过掉//pat的数据非常的坑,坑点十足,拿分不难,满分很难//解题思路://题意是给定一个数和其进制,找到使另一个数与其相等的进制//那么将给定的数转化成十进制,再使用二分查找另一个数的进制//坑点:转换回十进制很容易就会越过数据大小,会有一组非常大的进制数据卡二分法,要输出满足的最小.
2021-05-14 17:53:04
130
原创 【洛谷】P1878 舞蹈课
#include <iostream>#include <cstdio>#include <queue>using namespace std;//模拟到头痛的一道题//有一点细节出错就会全WA,自己思考不够全面细致的问题在这道题暴露的淋漓尽致//解题思路://建堆,然后每次得到差值最小的pop,再从两边找没有出列过的,并且异性的两个#define abs(x) (x) < 0? -(x) : (x)inline void read(int .
2021-05-13 12:43:21
298
原创 【PAT】1009 Product of Polynomials
#include <iostream>#include <cstdio>#include <map>using namespace std;//简单题,用map存多项式,模拟计算即可//正规解法似乎是自己手写建立链表存储,然后再模拟,虽然麻烦,但是可以用来熟悉链表的使用,这里用的是STL//要注意的是,例如if(mp[0] == 0);这种语句都会在map中创建一个为零项的项//输出的时候是需要把这些运算或各种原因变为零的项给去掉的inline vo.
2021-05-12 12:39:05
55
原创 【洛谷】[最短路]P1629邮递员送信
#include <iostream>#include <cstdio>#include <vector>#include <queue>#include <cstring>using namespace std;//此题有坑点:可能有多条不同权值的重边,因为这道题无负权,所以不需要标记,也不可以标记//解题思路:jijkstra裸题,有所不同的是还需要沿另一条路径回来而不是原路返回,则需要反向建图,得到返回时各点距离cons.
2021-05-12 11:05:03
134
原创 【PAT】1007 Maximum Subsequence Sum
#include <iostream>#include <cstdio>using namespace std;// 题意是求最大子序列,用贪心法即可//有所不同的是也要求最大子序列的两个端点//题目不难,细节很麻烦,直接存在一个数组里再求解可以避开很多麻烦点//我这里选择的是边读入边计算,所以多了很多麻烦的判断,以及记录全为负数时两个端点inline int read(){ register int x = 0, f = 1; register.
2021-05-11 16:44:15
59
原创 【洛谷】P3884二叉树问题
#include <iostream>#include <cstdio>#include <vector>using namespace std;//解题思路://倍增法打表求最近公共祖先//倍增法原理:任何一个数都可以由二进制数组成、表示,则最近祖先的距离也可以分成2的幂次的各个段落//其实这道题可以不用lca求解,因为数据较弱,只需求一组的lca//所以也可以不用这种方法,反向建图dfs暴力求解应该也可以inline void read(int.
2021-05-11 15:44:44
120
原创 【PAT】1005 Spell It Right
#include <cstdio>#include <iostream>#include <sstream>using namespace std;//简单题//但是花了我很多时间在一些细枝末节上//例如输入的结束控制,输出方法的选取//告诫:语法要熟练,思路要清晰//enum num {none, one, two, three, four, five, six, seven,eight, nine, ten,eleven, twelve, thi.
2021-05-10 12:12:07
61
原创 【洛谷】P3865-ST表模板
#include <iostream>#include <cstdio>using namespace std;//倍增法打表(类dp)//建表复杂度为o(nlog(n)),查询复杂度为o(1)#define max(x, y) (x) > (y)? (x) : (y)const int maxn = 1e5 + 5;inline void read(int &x){ register int f = 1; x = 0; re.
2021-05-10 11:00:49
87
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人