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 between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length…
1034. Head of a Gang (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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.…
PAT甲级1034. Head of a Gang 题意: 警方找到一个帮派的头的一种方式是检查人民的电话.如果A和B之间有电话,我们说A和B是相关的.关系的权重被定义为两人之间所有电话的总时间长度. "帮派"是超过2人的群体,彼此相关,总关系权重大于给定的阈值K.在每个帮派中,最大总重量的人是头.现在给了一个电话列表,你应该找到帮派和头. 输入规格: 每个输入文件包含一个测试用例. 对于每种情况,第一行分别包含两个正数N和K(均小于或等于1000),电话号码和权重.然后N行遵循以下格…
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 between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of…
1064 Complete Binary Search Tree (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 the node's key. The right subtree of a…
1053 Path of Equal Weight (30 分)   Given a non-empty tree with root R, and with weight W​i​​ assigned to each tree node T​i​​. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from R to any leaf…
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-87 or 0…
题意: 输入两个正整数N和K(<=1000),接下来输入N行数据,每行包括两个人由三个大写字母组成的ID,以及两人通话的时间.输出团伙的个数(相互间通过电话的人数>=3),以及按照字典序输出团伙老大的ID和团伙的人数(团伙中通话时长最长的人视为老大,数据保证一个团伙仅有一名老大). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; string s…
题目 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 the total time length of all the phone calls mad…
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805456881434624 题意: 给定n条记录(注意不是n个人的记录),两个人之间的关系的权值为这两个人之间所有电话记录的时间之和. 一个连通块的权值为所有关系权值之和. 如果一个连通块节点数大于2,且权值大于给定的k,称这是一个gang,拥有关系权值和最多的人是gang的头. 要求输出gang的数量,每个gang的头,每个gang的人数.按照gang的头的字典…
题目如下: 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 the total time length of all the phone calls…
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 the total time length of all the phone calls made b…
题意: 输入一个正整数N(<=30),接着输入两行N个正整数第一行为先序遍历,第二行为后续遍历.输出是否可以构造一棵唯一的二叉树并输出其中一颗二叉树的中序遍历. trick: 输出完毕中序遍历后须换行,否则所有测试点格式错误. #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],post[]; map<int,int>mp; int flag; vector<int>…
题意:输入两个正整数N和K(N<=1e4,K<=8e4),接着输入N行数据每行包括三个字符串表示车牌号,当前时间,进入或离开的状态.接着输入K次询问,输出当下停留在学校里的车辆数量.最后一行输出总计停留时间最长的车牌号(字典序升序输出)和停留总时. AAAAAccepted code: //因为一天只有86400秒,所以可以用一个car数组在统计车辆停留时间时在进入时间+1,离开时间-1.再用一个sum数组扫一遍,sum[i]=sum[i-1]+car[i],即可表示当下时间有多少辆车还在停留…
题意: 输入两个正整数N和L(N<=1000,L<=6),接着输入N行数据每行包括它关注人数(<=100)和关注的人的序号,接着输入一行包含一个正整数K和K个序号.输出每次询问的人发出消息经过至多L层转发最多有多少人转发. trick: 逻辑搞错的程序也能得到25或28分... AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ][]; ve…
题意: 输入两个正整数N和M(N<=10000,M<=10000),接着输入N个正整数.输出最小的序列满足序列和为M. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; ][]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m…
题意: 输入一个正整数N(<=200),代表颜色总数,接下来输入一个正整数M(<=200),代表喜爱的颜色数量,接着输入M个正整数表示喜爱颜色的编号(同一颜色不会出现两次),接下来输入一个正整数L(<=10000),代表条带的长度,接着输入L个正整数表示条带上的颜色的编号.输出以喜爱颜色顺序排列的最长子串长度(不必每种颜色都有,只保证相对位置相同,同种颜色可连续). AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<b…
题意: 输入四个正整数C,N,S,M(c<=100,n<=500),分别表示每个自行车站的最大容量,车站个数,此次行动的终点站以及接下来的M行输入即通路.接下来输入一行N个正整数表示每个自行车站初始拥有的自行车数量,接下来输入M行每行包含三个正整数分别表示一条双向边的端点以及这条路的长度.求去往终点车站一次所经历的最短路,多条最短路则优先少带出车辆,次优先少带回车辆.(路上经过站点时需要把该站点的车辆变为最大容量的一半) AAAAAccepted code: #include<bits/…
题面: 输入四个正整数N,M,K,Q(N<=20,M<=10,K,Q<=1000),N为银行窗口数量,M为黄线内最大人数,K为需要服务的人数,Q为查询次数.输入K个正整数,分别代表每位顾客需要被服务的时间,Q次查询每次查询一位顾客被服务完离开银行的时间.如果他在五点以前(不包括五点)没有开始被服务,输出“Sorry”. trick: 在五点以前(不包括五点)没有开始被服务,输出“Sorry”,而不是被服务完时间在五点以后(以题面为准). AAAAAccepted code: #inclu…
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, ... where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth number. For ex…
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students. Input Specification: Each input file contains one test case. Each cas…
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the loca…
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 standard routine to print the numbers in level-order. H…
1119 Pre- and Post-order Traversals (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, or preorder and inorder travers…
1095 Cars on Campus (30 分) Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at…
题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1034 此题考查并查集的应用,要熟悉在合并的时候存储信息: #include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <cstddef> using namespace std; struc…
给出n和k接下来n行,每行给出a,b,c,表示a和b之间的关系度,表明他们属于同一个帮派一个帮派由>2个人组成,且总关系度必须大于k.帮派的头目为帮派里关系度最高的人.(注意,这里关系度是看帮派里边的和,而不是帮派里所有个人的总和.如果是按个人算的话,相当于一条边加了两次,所以应该是>2*k)问你有多少个合格帮派,以及每个帮派里最大的头目是谁,按字典序输出 先并查集一下,然后统计每个帮的成员数.总关系度.以及头目 #include <iostream> #include <c…
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<string> #include<queue> #include<stack> #include<algorithm> #include<iostream> using namespace st…
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 the total time length of all the phone calls made b…
分析: 考察并查集,注意中间合并时的时间的合并和人数的合并. #include <iostream> #include <stdio.h> #include <algorithm> #include <cstring> #include <string> #include <vector> #include <cctype> #include <map> using namespace std; const i…