
PTA
Jcldcdmf
haha
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2...原创 2020-04-29 11:48:32 · 233 阅读 · 0 评论 -
1054 The Dominant Color (20分)
Behind the scenes in the computer’s memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the d...原创 2020-04-22 11:10:45 · 132 阅读 · 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 ...原创 2020-04-17 11:00:12 · 258 阅读 · 0 评论 -
1038 Recover the Smallest Number (30分)cmp函数
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...原创 2020-04-16 12:17:15 · 126 阅读 · 0 评论 -
1034 Head of a Gang (30 分)dfs或并查集
One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be t...原创 2020-04-12 21:47:23 · 190 阅读 · 0 评论 -
1014 Waiting in Line (30分)队列的应用
Suppose a bank has N windows 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 ...原创 2020-04-03 11:53:42 · 332 阅读 · 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...原创 2020-04-02 21:27:47 · 184 阅读 · 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), and E - Eng...原创 2020-04-02 15:14:15 · 271 阅读 · 0 评论 -
1004 Counting Leaves (30 分)
一、题目大意:输入节点个数n和非叶节点个数m,并在接下来的m行中以如下形式输入节点id的子节点:id 子节点个数 子节点1 子节点2……。要求输出每一层中叶节点(没有孩子的节点)的个数。二、有问题的思路和代码#include <iostream>using namespace std;#define MaxNum 101typedef struct Node{ ...原创 2019-05-26 17:21:44 · 1837 阅读 · 3 评论 -
1135 Is It A Red-Black Tree (30分)
There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties:(1) Every node is either red or black.(2) The root is black.(3) Every le...原创 2020-03-27 22:19:53 · 312 阅读 · 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 in...原创 2020-03-26 12:09:08 · 133 阅读 · 0 评论 -
1068 Find More Coins (30分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...原创 2020-03-25 17:10:06 · 179 阅读 · 0 评论 -
1123 Is It a Complete AVL Tree (30分)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is...原创 2020-03-25 15:48:16 · 205 阅读 · 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 ...原创 2020-03-24 22:25:41 · 188 阅读 · 0 评论 -
1017 Queueing at Bank (25分)
Suppose a bank has K windows 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...原创 2020-03-24 11:55:39 · 138 阅读 · 0 评论 -
1111 Online Map (30分)
Input our current position and a destination, an online map can recommend several paths. Now your job is to recommend two paths to your user: one is the shortest, and the other is the fastest. It is g...原创 2020-03-23 18:35:48 · 195 阅读 · 0 评论 -
1110 Complete Binary Tree (25分)
Given a tree, you are supposed to tell if it is a complete binary tree.Input Specification:Each input file contains one test case. For each case, the first line gives a positive integer N (≤20) whic...原创 2020-03-23 16:22:32 · 221 阅读 · 0 评论 -
1109 Group Photo (25分)
Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:The number of people in each row must be N/K (round down to the nearest integer...原创 2020-03-23 13:53:59 · 350 阅读 · 0 评论 -
1108 Finding Average (20分)
The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A legal input is a real...原创 2020-03-22 11:07:11 · 215 阅读 · 0 评论 -
1115 Counting Nodes in a BST (30分)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than or equal to the node’s key.Th...原创 2020-03-21 19:26:38 · 133 阅读 · 0 评论 -
1112 Stucked Keyboard (20分)
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.Now given a resulti...原创 2020-03-21 14:15:43 · 134 阅读 · 0 评论 -
1127 ZigZagging on a Tree (30分)
Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder traversal sequences. And it is a simple stand...原创 2020-03-16 10:56:47 · 290 阅读 · 0 评论 -
1139 First Contact (30分)
注意不能用int输入编号,否则-0000与0000无法区分性别,这可能是第1、2(从0开始)测点错误的原因1139 First Contact (30 分)(细节坑题)转载 2020-03-11 23:46:51 · 574 阅读 · 0 评论 -
1138 Postorder Traversal (25分)
Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal se...原创 2020-03-11 22:03:06 · 156 阅读 · 0 评论 -
1142 Maximal Clique (25分)
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adj...原创 2020-03-10 17:49:36 · 160 阅读 · 0 评论 -
1141 PAT Ranking of Institutions (25分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist.Input Specification:Each input file contain...原创 2020-03-10 16:43:49 · 135 阅读 · 0 评论 -
1145 Hashing - Average Search Time (25分)
The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average sea...原创 2020-03-10 00:28:18 · 147 阅读 · 0 评论 -
1151 LCA in a Binary Tree (30分)
自己写的:先建树,然后利用后续非递归遍历求解#include<iostream>#include<stack>using namespace std;const int maxn = 10010;typedef struct node { int n; node* left; node* right;}*tree;int n, m, pre[maxn...原创 2020-03-09 15:51:16 · 247 阅读 · 0 评论 -
1154 Vertex Coloring (25分)
此题与图算法基本无关存储所有边,存储所有顶点的颜色,枚举每一条边,判断该边两顶点颜色是否相同。#include<iostream>#include<set>using namespace std;const int maxn = 10010;int n, m;set<int>s;struct { int vex1; int vex2;}ed...原创 2020-03-04 00:45:10 · 105 阅读 · 0 评论 -
1089 Insert or Merge (25分)
需要注意的地方就是,the initial sequence至少要经过一次排序后才能与the partially sorted sequence比较,否则当输入的两组数据顺序相同时,无法判断是哪种排序。#include<iostream>#include<algorithm>using namespace std;const int maxn = 110;int...原创 2020-02-25 17:29:30 · 148 阅读 · 0 评论 -
1033 To Fill or Not to Fill (25分)
思路:总体来说是用贪心策略,即尽可能地选择油价最低的加油站来加油。假设车辆现位于加油站s(不是最后一个加油站), 情况可以分为如下:Ⅰ、在车辆可达的范围(即在s处加满油后,能走的最远距离)内,没有加油站,……。Ⅱ、在车辆可达的范围(即在s处加满油后,能走的最远距离)内,有加油站s0的油价低于s处,那么,就在s处加油,使车辆恰好能到达s0。Ⅲ、在车辆可达的范围(即在s处加满油后,能走的最远距...原创 2020-02-23 17:17:50 · 162 阅读 · 0 评论 -
1042 Shuffling Machine (20 分)
#include<iostream>struct card{ int num; char mark;//S,H,C,D};using namespace std;void sort_card(card*init,int order[],card*changed){ for (int i = 1; i <= 54; ++i) chan...原创 2019-08-23 17:13:37 · 163 阅读 · 0 评论 -
1046 Shortest Distance (20 分)
注意为防止超时,输入时做预处理#include <iostream>using namespace std;struct exit_pair{ int e1,e2;};int main(){ int N; cin>>N; int distance; long long int sum[N+1]; sum[0]=0;...原创 2019-08-23 17:12:28 · 121 阅读 · 0 评论 -
1016 Phone Bills (25 分)电话费计算
一、问题二、分析名字不同的人按名字的字典顺序排序,名字相同的人按输入时间排序。三、注意并不是每个人都至少有一通电话接通,而是N个人里至少有一通电话接通;计算一次通话的费用时,分别计算从00.00.00到开始时间和从00.00.00到结束时间的费用,再作差,比直接计算要简单。四、代码#include <iostream>#include <vector>#...原创 2019-08-07 18:39:34 · 526 阅读 · 0 评论 -
1015 Reversible Primes (20 分)
prime:素数#include <iostream>#include <queue>using namespace std;bool isPrime(int N){ if(N<=1)return false; if(N==2)return true; for (int i = 2; i <= N/2; ++i) { ...原创 2019-08-06 21:51:36 · 87 阅读 · 0 评论 -
1010 Radix (25 分)
一、问题描述输入两个数N1、N2,和一个标记tag、一个基数radix,其意义是:tag为1时,radix是N1的基数;tag为2时,radix是N2的基数。方便起见,以下假定tag为1,则目标就是找到一个尽可能小的基数,使N2在此基数下的值等于N1在radix下的值。例如二进制下的110等于十进制下的6。二、思路做过的都知道,思路是不难的,就是坑实在不少,要想的全面一点。1、暴力算法:...原创 2019-06-10 17:31:58 · 6384 阅读 · 6 评论 -
1008 Elevator
不要忘记电梯原地停留的情况#include<iostream>using namespace std;int main(){ int n; cin>>n; int pasgers[n]; int sum=0; int pre=0; for(int i=0;i<n;i++){ cin>>pasgers[i]; if(pasgers...原创 2019-06-03 09:12:52 · 115 阅读 · 0 评论 -
1006 Sign In and Sign Out (25 分)
#include <iostream>#include <string>using namespace std;typedef struct Person{ string ID=""; string sign_in=""; string sign_out="";}*Records;int main(){ int num_of_pe...原创 2019-05-30 08:11:41 · 185 阅读 · 0 评论 -
1005 Spell It Right (20 分)
#include <iostream>#include <stack>#include <string>using namespace std;int main(){ int sum=0; char num; while((num=getchar())!='\n'){ sum+=num-'0'; }...原创 2019-05-28 20:04:21 · 155 阅读 · 0 评论 -
1013 Battle Over Cities (25 分)
一、题目二、思路把这些城市看做n个集合,每个集合中的任意两个元素都有直接或间接的路径相连,不同集合中的任意两个元素之间没有任何路径。这样每两个城市都连通就等价于任意两个集合都连通,共需要n-1条路,至于被占领的那个城市L,将其他城市与L之间的路(直接相连的)都断开,这样L单独构成一个集合,最后输出的时候减去这个集合就行了。三、代码#include<iostream>#incl...原创 2019-06-12 14:54:02 · 317 阅读 · 2 评论