One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the stroke core.
Each input file contains one test case. For each case, the first line contains 4 positive integers: M, N, L and T, where M and N are the sizes of each slice (i.e. pixels of a slice are in an M×N matrix, and the maximum resolution is 1286 by 128); L (≤60) is the number of slices of a brain; and T is the integer threshold (i.e. if the volume of a connected core is less than T, then that core must not be counted).
Then L slices are given. Each slice is represented by an M×N matrix of 0’s and 1’s, where 1 represents a pixel of stroke, and 0 means normal. Since the thickness of a slice is a constant, we only have to count the number of 1’s to obtain the volume. However, there might be several separated core regions in a brain, and only those with their volumes no less than T are counted. Two pixels are connectedand hence belong to the same region if they share a common side, as shown by Figure 1 where all the 6 red pixels are connected to the blue one.
For each case, output in a line the total volume of the stroke core.
1  3 4 5 2 
1  26 
开始使用的是dfs
，类似于dfs
求解连通块的算法，但是发现dfs
无论怎么修改后面两组数据总是出现段错误，但是计算后面的内存使用情况也没有超过64M
,所以打算换用bfs
求解，使用bfs
可以得到正确结果
dfs
程序只得到了25
分，并没有满分，如果有修改并可以通过的地方，感觉大家的指点
1 

1 

Given a tree, you are supposed to tell if it is a complete binary tree.
Each input file contains one test case. For each case, the first line gives a positive integer N (≤20) which is the total number of nodes in the tree – and hence the nodes are numbered from 0 to N−1. Then N lines follow, each corresponds to a node, and gives the indices of the left and right children of the node. If the child does not exist, a 
will be put at the position. Any pair of children are separated by a space.
For each case, print in one line YES
and the index of the last node if the tree is a complete binary tree, or NO
and the index of the root if not. There must be exactly one space separating the word and the number.
1  9 
1  YES 8 
1  8 
1  NO 1 
本题给出每个节点的子节点，要求判断此树是否为完全二叉树
第一种思路是使用BFS，最直接的思路判断是否为完全二叉树，依次向下遍历节点，总共分为四种类型的节点：
既包含左子节点又包含右子节点、只包含左子节点、只包含右子节点、以及不包含子节点
其中只要出现只包含右子节点的情况，就表明一定不是完全二叉树，当出现只包含左子节点或者不包含子节点的情况，就表明后面（按照层次遍历的顺序）的节点都是叶子节点，即能为不包含子节点的情况
第二种思路为，按照层次遍历的顺序（如果不存在节点，也要进行遍历），当出现不是节点的时候，判断遍历节点的个数，如果等于给定的n，那么表明为此树为完全二叉树，如果不等于n，则表明不是完全二叉树
思路一
1 

思路二
1 

Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:
Now given the information of a group of people, you are supposed to write a program to output their formation.
Each input file contains one test case. For each test case, the first line contains two positive integers N (≤104), the total number of people, and K (≤10), the total number of rows. Then N lines follow, each gives the name of a person (no more than 8 English letters without space) and his/her height (an integer in [30, 300]).
For each case, print the formation – that is, print the names of people in K lines. The names must be separated by exactly one space, but there must be no extra space at the end of each line. Note: since you are facing the group, people in the rear rows must be printed above the people in the front rows.
1  10 3 
1  Bob Tom Joe Nick 
按照身高对人进行排序，如果身高相同，则根据名字进行排序，给出人的数量以及要排列的行数，假设n
行，一共m
人，前n1
行，每行m/n
人，剩余全部安排在第n
行，每一行中最高的放在（m/n/2 + 1）
位置处，然后根据高度排序依次向其左右安排人站的位置
只需要sort进行排序后，模拟一下这个过程即可
1 

For a student taking the online course “Data Structures” on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a final grade no less than 60 out of 100. The final grade is calculated by G=(Gmid−term×40%+Gfinal×60%) if Gmid−term>Gfinal, or Gfinal will be taken as the final grade G. Here Gmid−term and Gfinal are the student’s scores of the midterm and the final exams, respectively.
The problem is that different exams have different grading sheets. Your job is to write a program to merge all the grading sheets into one.
Each input file contains one test case. For each case, the first line gives three positive integers: P , the number of students having done the online programming assignments; M, the number of students on the midterm list; and N, the number of students on the final exam list. All the numbers are no more than 10,000.
Then three blocks follow. The first block contains P online programming scores Gp’s; the second one contains M midterm scores Gmid−term’s; and the last one contains N final exam scores Gfinal’s. Each score occupies a line with the format: StudentID Score
, where StudentID
is a string of no more than 20 English letters and digits, and Score
is a nonnegative integer (the maximum score of the online programming is 900, and that of the midterm and final exams is 100).
For each case, print the list of students who are qualified for certificates. Each student occupies a line with the format:
StudentID
Gp Gmid−term Gfinal G
If some score does not exist, output “−1” instead. The output must be sorted in descending order of their final grades (G must be rounded up to an integer). If there is a tie, output in ascending order of their StudentID
‘s. It is guaranteed that the StudentID
‘s are all distinct, and there is at least one qullified student.
1  6 6 7 
1  missing 400 1 99 99 
注意：只有当成绩不存在的时候，输出‘1’，当成绩为0时，需要继续输出0
可以推断出，只有当编程成绩大于200时，成绩才会有效，所以我们将编程成绩小于200的学生放在数组0处，不予以编号
计算最后成绩时，四舍五入直接在double基础上+0.5，自动准换为int即可
1 

Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the nonnegatives, and all the values in [0, K] appear before all those greater than K. The order of the elements inside each class must not be changed. For example, given the list being 18→7→4→0→5→6→10→11→2 and K being 10, you must output 4→6→2→7→0→5→10→18→11.
Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (≤105) which is the total number of nodes, and a positive K (≤103). The address of a node is a 5digit nonnegative integer, and NULL is represented by −1.
Then N lines follow, each describes a node in the format:
1  Address Next 
where Address
is the position of the node, Data
is an integer in [−105,105], and Next
is the position of the next node. It is guaranteed that the list is not empty.
For each case, output in order (from beginning to the end of the list) the resulting linked list. Each node occupies a line, and is printed in the same format as in the input.
1  00100 9 10 
1  33218 4 68237 
可以发现，将所有节点分为三部分，首先是小于0，第二部分为大于等于0且小于等于k，第三部分为大于k的，我们需要将相同部分交换到相邻位置，可以直接使用三个queue来进行模拟即可
1 

A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.
Each input file contains one test case. Each case starts with two positive integers N (<100) which is the total number of family members in the tree (and hence assume that all the members are numbered from 01 to N), and M (<N) which is the number of family members who have children. Then M lines follow, each contains the information of a family member in the following format:
1  ID K ID[1] ID[2] ... ID[K] 
where ID
is a twodigit number representing a family member, K
(>0) is the number of his/her children, followed by a sequence of twodigit ID
‘s of his/her children. For the sake of simplicity, let us fix the root ID
to be 01
. All the numbers in a line are separated by a space.
For each test case, print in one line the largest population number and the level of the corresponding generation. It is assumed that such a generation is unique, and the root level is defined to be 1.
1  23 13 
1  9 4 
给出树中每个节点的子节点，并且根节点为01，求解树中包含节点最多的一层以及节点数量
在跟节点开始，BFS向深处遍历，即可得到每一层包含的节点，判断出包含最多的一层即可
1 

The string APPAPT
contains two PAT
‘s as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.
Now given any string, you are supposed to tell the number of PAT
‘s contained in the string.
Each input file contains one test case. For each case, there is only one line giving a string of no more than 105 characters containing only P
, A
, or T
.
For each test case, print in one line the number of PAT
‘s contained in the string. Since the result may be a huge number, you only have to output the result moded by 1000000007.
1  APPAPT 
1  2 
求出一个字符串中所包含的连续或不连续的子串”PAT”的个数， 首先想到的是遍历字符串中的P，然后确定A，最后寻找T，确定前面两个，子串个数为A位置后面T字符的个数，但是这样的思路，时间复杂度为O(n^2)，时间应该会超限
既然确定P时间复杂度很高，我们可以确定中间的A，做一次预处理，求出A位置之前的P出现的次数，A位置之后T出现的次数，这样将两个出现的次数相乘，即可确定当前中间A固定的子串PAT的个数
1 

1146 Topological Order （25 分）
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options.
Each input file contains one test case. For each case, the first line gives two positive integers N (≤ 1,000), the number of vertices in the graph, and M (≤ 10,000), the number of directed edges. Then M lines follow, each gives the start and the end vertices of an edge. The vertices are numbered from 1 to N. After the graph, there is another positive integer K (≤ 100). Then K lines of query follow, each gives a permutation of all the vertices. All the numbers in a line are separated by a space.
Print in a line all the indices of queries which correspond to “NOT a topological order”. The indices start from zero. All the numbers are separated by a space, and there must no extra space at the beginning or the end of the line. It is graranteed that there is at least one answer.
1  6 8 
1  3 4 
要求判断给出的每一个序列是否符合拓扑序列 ，要解决这个问题首先要知道拓扑排序怎么计算
拓扑排序首先我们将有向图的每一个节点的入度计算出来，找出入度为0的节点，表示没有节点必须要出现在它前面（即可以将此节点作为下一个输出的节点，这里我们就可以得到拓扑排序的答案不是唯一的），并且将以此节点指向的节点的入度进行1，依次向下判断则得出拓扑排序
现在我们将上诉过程变更为判断性的即可
1 

1144 The Missing Number （20 分）
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.
Each input file contains one test case. For each case, the first line gives a positive integer N (≤105). Then N integers are given in the next line, separated by spaces. All the numbers are in the range of int.
Print in a line the smallest positive integer that is missing from the input list.
1  10 
1  7 
寻找不出现在列表中的最小的数字，那么直接暴力判断有没有出现在列表中即可
1 

Some scientists took pictures of thousands of birds in a forest. Assume that all the birds appear in the same picture belong to the same tree. You are supposed to help the scientists to count the maximum number of trees in the forest, and for any pair of birds, tell if they are on the same tree.
Each input file contains one test case. For each case, the first line contains a positive number N (≤104) which is the number of pictures. Then N lines follow, each describes a picture in the format:
K B1 B2 … BK
where K is the number of birds in this picture, and Bi’s are the indices of birds. It is guaranteed that the birds in all the pictures are numbered continuously from 1 to some number that is no more than 104.
After the pictures there is a positive number Q (≤104) which is the number of queries. Then Q lines follow, each contains the indices of two birds.
For each test case, first output in a line the maximum possible number of trees and the number of birds. Then for each query, print in a line Yes
if the two birds belong to the same tree, or No
if not.
1  4 
1  2 10 
题目指出，出现在同一张图片中的鸟则表示在一棵树上，那么每一行表示出现在同一张图片中鸟的编号，要求判断一共多少棵树以及多少只鸟，并且任意给出两个鸟的编号，判断是否在同一颗树上面
并查集的思路为：以每一棵树中第一个出现的鸟为父节点，后面所有的鸟为子节点，做出一棵树，并且更新per数组，那么这样做过所有照片，则所有的鸟就做出了一棵树，判断每一只鸟对应的per数组是否等于其编号，如果相等，则表示它及它的子节点在同一颗树上，这样计算树的个数即可
1 

“Let’s C” is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny as the following:
Given the final ranklist and a sequence of contestant ID’s, you are supposed to tell the corresponding awards.
Each input file contains one test case. For each case, the first line gives a positive integer N (≤104), the total number of contestants. Then N lines of the ranklist follow, each in order gives a contestant’s ID (a 4digit number). After the ranklist, there is a positive integer K followed by K query ID’s.
For each query, print in a line ID: award
where the award is Mystery Award
, or Minion
, or Chocolate
. If the ID is not in the ranklist, print Are you kidding?
instead. If the ID has been checked before, print ID: Checked
.
1  6 
1  8888: Minion 
直接根据题目中的要求进行模拟即可
首先根据排名给出选手的id
，第一名会获得 Mystery Award
，排名为素数的会获得Minion
,其余则获得Chocolate
,如果查询的id
没有再排名中给出，则输出Are you kidding?
，如果后面重复查询某个选手所获得的奖励则输出Checked
1 

本题可以使用简单的方法进行素数判定，如果需要判断某区间内所有素数，那么可以使用Euler筛法
]]>The “Hamilton cycle problem” is to find a simple cycle that contains every vertex in a graph. Such a cycle is called a “Hamiltonian cycle”.
In this problem, you are supposed to tell if a given cycle is a Hamiltonian cycle.
Each input file contains one test case. For each case, the first line contains 2 positive integers N (2<N≤200), the number of vertices, and M, the number of edges in an undirected graph. Then M lines follow, each describes an edge in the format Vertex1 Vertex2
, where the vertices are numbered from 1 to N. The next line gives a positive integer K which is the number of queries, followed by K lines of queries, each in the format:
n V1 V2 … Vn
where n is the number of vertices in the list, and Vi’s are the vertices on a path.
For each query, print in a line YES
if the path does form a Hamiltonian cycle, or NO
if not.
1  6 10 
1  YES 
要求判断给出的路径是否为哈密顿回路，那么哈密顿回路应该满足：
1 

哈密顿回路 百度百科
]]>“Damn Single (单身狗)” is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.
Each input file contains one test case. For each case, the first line gives a positive integer N (≤ 50,000), the total number of couples. Then N lines of the couples follow, each gives a couple of ID’s which are 5digit numbers (i.e. from 00000 to 99999). After the list of couples, there is a positive integer M (≤ 10,000) followed by M ID’s of the party guests. The numbers are separated by spaces. It is guaranteed that nobody is having bigamous marriage (重婚) or dangling with more than one companion.
First print in a line the total number of lonely guests. Then in the next line, print their ID’s in increasing order. The numbers must be separated by exactly 1 space, and there must be no extra space at the end of the line.
1  3 
1  5 
题目中给出n对夫妇，然后给出m个来聚会的人，找出来聚会中单身的人，如果情侣没有来，那么也算单身
可以使用map存储上面的夫妇信息，也可以直接使用数组进行保存， 然后再来聚会的人中，依次遍历，如果不存在伴侣则直接保存到另一个vector中，否则判断自己的情侣有没有来
1 

A 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 chain buys products from one’s supplier in a price P and sell or distribute them in a price that is r% higher than P. It is assumed that each member in the supply chain has exactly one supplier except the root supplier, and there is no supply cycle.
Now given a supply chain, you are supposed to tell the highest price we can expect from some retailers.
Each input file contains one test case. For each case, The first line contains three positive numbers: N (≤105), the total number of the members in the supply chain (and hence they are numbered from 0 to N−1); P, the price given by the root supplier; and r, the percentage rate of price increment for each distributor or retailer. Then the next line contains N numbers, each number Si is the index of the supplier for the ith member. Sroot for the root supplier is defined to be −1. All the numbers in a line are separated by a space.
For each test case, print in one line the highest price we can expect from some retailers, accurate up to 2 decimal places, and the number of retailers that sell at the highest price. There must be one space between the two numbers. It is guaranteed that the price will not exceed 1010.
1  9 1.80 1.00 
1  1.85 2 
题目中给出每一个营销链中他的上一级，并且没经过一次中间商产品价格就会增加r%，产品的基本价格为p，并且只包含一个供应商，它以1来进行标识
我们需要求出最大的营销链深度，及最大深度下零售店的个数，最后输出两个值
这个题我们既可以使用dfs求解，也可以使用bfs求解，因为本人感觉bfs的程序更容易理解，所以采用bfs进行求解
1 
