![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
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 top position) and Po...原创 2019-08-17 21:45:46 · 90 阅读 · 0 评论 -
1076 Forwards on Weibo (30 分)
Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a ...原创 2019-08-09 21:30:28 · 170 阅读 · 0 评论 -
1087 All Roads Lead to Rome (30 分)
Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the route with the least cost while gaining the most happiness.Input Specification:Each ...原创 2019-08-13 23:42:13 · 58 阅读 · 0 评论 -
1072 Gas Station (30 分)
A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the hou...原创 2019-08-13 22:07:21 · 87 阅读 · 0 评论 -
1034 Head of a Gang (30 分)
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call betweenAandB, we say thatAandBis related. The weight of a relation is defined to be t...原创 2019-08-08 19:35:19 · 98 阅读 · 0 评论 -
1025 反转链表 (25 分)
给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为 1→2→3→4→5→6,K为 3,则输出应该为 3→2→1→6→5→4;如果K为 4,则输出应该为 4→3→2→1→5→6,即最后不到K个元素不反转。输入格式:每个输入包含 1 个测试用例。每个测试用例第 1 行给出第 1 个结点的地址、结点总个数正整数N(≤105)、以及...原创 2019-08-01 22:49:38 · 77 阅读 · 0 评论 -
1056 Mice and Rice (25 分)
Mice and Riceis the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice...原创 2019-08-01 21:44:36 · 63 阅读 · 0 评论 -
1044 Shopping in Mars (25 分)
Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position ...原创 2019-07-27 23:18:43 · 57 阅读 · 0 评论 -
Radix (25 分)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer isyes, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive inte...原创 2019-07-27 22:56:29 · 134 阅读 · 0 评论 -
完美数列 (25 分)
给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M≤mp,则称这个数列是完美数列。现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。输入格式:输入第一行给出两个正整数N和p,其中N(≤105)是输入的正整数的个数,p(≤109)是给定的参数。第二行给出N个正整数,每个数不超过109。输出格式:...原创 2019-07-27 21:38:43 · 72 阅读 · 0 评论 -
1051 Pop Sequence (25 分)
Given a stack which can keepMnumbers at most. PushNnumbers in the order of 1, 2, 3, ...,Nand pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of t...原创 2019-07-31 22:59:01 · 76 阅读 · 0 评论 -
简易计算器
#include <iostream>#include <stack>#include <queue>#include <map> using namespace std;map<char, int> op;string str;struct node { double num; char op; bool fl...原创 2019-07-31 22:09:33 · 88 阅读 · 0 评论 -
1038 Recover the Smallest Number (30 分)
Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229...原创 2019-07-26 23:17:01 · 69 阅读 · 0 评论 -
1067 Sort with Swap(0, i) (25 分)
Given any permutation of the numbers {0, 1, 2,...,N−1}, it is easy to sort them in increasing order. But what ifSwap(0, *)is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2...原创 2019-07-26 22:52:26 · 53 阅读 · 0 评论 -
1037 Magic Coupon (25 分)
The magic shop in Mars is offering some magic coupons. Each coupon has an integerNprinted on it, meaning that when you use this coupon with a product, you may getNtimes the value of that product b...原创 2019-07-26 22:27:12 · 53 阅读 · 0 评论 -
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 ga...原创 2019-07-26 22:05:33 · 62 阅读 · 0 评论 -
1022 Digital Library (30 分)
A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is assigned an unique 7-digit number a...原创 2019-07-31 21:18:28 · 89 阅读 · 0 评论 -
1012 The Best Rank (25 分)
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:C- C Programming Language,M- Mathematics (Calculus or Linear Algrbra), andE- Eng...原创 2019-07-23 08:20:49 · 53 阅读 · 0 评论 -
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 nee...原创 2019-08-09 21:55:41 · 203 阅读 · 0 评论 -
1021 Deepest Root (25 分)
A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root ...原创 2019-08-09 22:23:04 · 79 阅读 · 0 评论 -
最长回文子串
#include <iostream>#include <cstring>using namespace std;const int N = 1010;char str[N];int dp[N][N];int main() { //patzjujztaccbcc scanf("%s", str); int len = strlen(str),...原创 2019-08-16 22:30:14 · 56 阅读 · 0 评论 -
最长公共子序列
#include <iostream>#include <cstring> using namespace std;const int N = 100;char a[N], b[N];int dp[N][N]; int main() { // asdstory adminsorry scanf("%s %s", a, b); int n = s...原创 2019-08-16 21:24:03 · 66 阅读 · 0 评论 -
1018 Public Bike Management (30 分)
There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the ...原创 2019-08-12 23:17:03 · 64 阅读 · 0 评论 -
Floyd
#include <iostream>#include <algorithm>using namespace std;const int N = 510;const int INF = 0x3fffffff;int n, m;int dis[N][N];void Floyd() { for (int k = 0; k < n; k++) {...原创 2019-08-12 21:41:09 · 69 阅读 · 0 评论 -
1045 Favorite Color Stripe (30 分)
Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts...原创 2019-08-15 22:28:33 · 89 阅读 · 0 评论 -
最长不下降子序列
#include <iostream>using namespace std;const int N = 100;int a[N], dp[N]; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]);...原创 2019-08-15 21:54:25 · 79 阅读 · 0 评论 -
1007 Maximum Subsequence Sum (25 分)
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequen...原创 2019-08-15 21:27:21 · 69 阅读 · 0 评论 -
SPFA
#include <iostream>#include <cstring>#include <vector>#include <algorithm>#include <queue>using namespace std;const int N = 510;const int INF = 0x3fffffff;stru...原创 2019-08-11 21:51:32 · 76 阅读 · 0 评论 -
1030 Travel Plan (30 分)(dijkstra+dfs)
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 b...原创 2019-08-11 21:24:57 · 73 阅读 · 0 评论 -
最大子段和
#include <iostream>using namespace std;int a[100], dp[100]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } dp[0] = a[0];...原创 2019-08-14 23:00:53 · 68 阅读 · 0 评论 -
数塔(dp)
#include <iostream>using namespace std; int main() { int f[10][10], dp[10][10]; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { scan...原创 2019-08-14 22:51:02 · 74 阅读 · 0 评论 -
1093 字符串A+B (20 分)
给定两个字符串A和B,本题要求你输出A+B,即两个字符串的并集。要求先输出A,再输出B,但重复的字符必须被剔除。输入格式:输入在两行中分别给出A和B,均为长度不超过106的、由可见 ASCII 字符 (即码值为32~126)和空格组成的、由回车标识结束的非空字符串。输出格式:在一行中输出题面要求的A和B的和。输入样例:This is a ...原创 2019-08-10 22:16:48 · 59 阅读 · 0 评论 -
1003 Emergency (25 分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the l...原创 2019-08-10 22:00:40 · 72 阅读 · 0 评论 -
Prim
#include <iostream>#include <algorithm>using namespace std;const int N = 510;const int INF = 0x3fffffff;int n, m, G[N][N];int d[N];bool vis[N] = {false};int path[N];int Prim(i...原创 2019-08-14 22:03:56 · 91 阅读 · 0 评论 -
kruskal
#include <iostream>#include <algorithm>using namespace std;const int N = 110;const int M = 10010;struct edge { int u, v; int cost;}E[M];int n, m;bool cmp(edge a, edge b) { ...原创 2019-08-14 22:03:20 · 69 阅读 · 0 评论 -
1017 Queueing at Bank (25 分)
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 li...原创 2019-08-19 22:22:21 · 91 阅读 · 0 评论 -
最短路径(迪杰斯特拉算法)
#include <iostream>#include <algorithm>using namespace std;const int maxn = 1000;const int INF = 1000000000;int Map[maxn][maxn];int n, m, s;int d[maxn];bool visited[maxn] = {fal...原创 2019-08-09 22:40:53 · 220 阅读 · 0 评论 -
1015 德才论 (25 分)
宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”现给出一批考生的德才分数,请根据司马光的理论给出录取排名。输入格式:输入第一行给出 3 个正整数,分别为:N(≤105),即考生总数;L(≥60),为录取最低分数线,即德分和才分均不低于L...原创 2019-07-22 23:03:41 · 140 阅读 · 0 评论 -
1079 Total Sales of Supply Chain (25 分)
supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the...原创 2019-08-04 21:43:06 · 63 阅读 · 0 评论 -
1009 说反话 (20 分)
给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过 80 的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用 1 个空格分开,输入保证句子末尾没有多余的空格。输出格式:每个测试用例的输出占一行,输出倒序后的句子。输入样例:Hello World Her...原创 2019-07-21 19:42:11 · 76 阅读 · 0 评论