
c++
小火汁猛猛
为中华之崛起而读书!自然语言处理硕士在读,未来的延毕er,曾经的暴雪粉,现主机玩家,文学爱好者,YOUNG OG,09年开始玩说唱。
展开
-
7-10 公路村村通 (30 分)(最小生成树)+prim详解
现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本。输入格式:输入数据包括城镇数目正整数N(≤1000)和候选道路数目M(≤3N);随后的M行对应M条道路,每行给出3个正整数,分别是该条道路直接连通的两个城镇的编号以及该道路改建的预算成本。为简单起见,城镇从1到N编号。输出格式:输出村村通需要的最低成本。如果输入数据...原创 2019-01-03 16:29:20 · 1066 阅读 · 0 评论 -
7-12 How Long Does It Take (25 分)(拓扑排序)+超详细注释
Given the relations of all the activities of a project, you are supposed to find the earliest completion time of the project.Input Specification:Each input file contains one test case. Each case s...原创 2019-01-03 20:03:21 · 1063 阅读 · 0 评论 -
7-12 排序 (25 分)(希尔排序模板,内赠插入排序模板)
给定N个(长整型范围内的)整数,要求输出从小到大排序后的结果。本题旨在测试各种不同的排序算法在各种数据情况下的表现。各组测试数据特点如下: 数据1:只有1个元素; 数据2:11个不相同的整数,测试基本正确性; 数据3:103个随机整数; 数据4:104个随机整数; 数据5:105个随机整数; ...原创 2019-01-03 22:37:45 · 258 阅读 · 0 评论 -
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,...原创 2019-01-04 11:15:34 · 342 阅读 · 0 评论 -
1098 Insertion or Heap Sort (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,...原创 2019-01-04 15:49:57 · 699 阅读 · 0 评论 -
回溯法解决八皇后(c++)
八皇后问题是一个以国际象棋为背景的问题:如何能够在 8×8 的国际象棋棋盘上放置八个皇后,使得任何一个皇后都无法直接吃掉其他的皇后?为了达到此目的,任两个皇后都不能处于同一条横行、纵行或斜线上。八皇后问题可以推广为更一般的n皇后摆放问题:这时棋盘的大小变为n1×n1,而皇后个数也变成n2。而且仅当 n2 ≥ 1 或 n1 ≥ 4 时问题有解。八皇后问题最早是由国际西洋棋棋手马克斯·贝瑟尔于18...原创 2018-12-30 20:29:45 · 774 阅读 · 4 评论 -
1075 PAT Judge (25 分)(排序,结构体)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist for PAT.Input Specification:Each input file co...原创 2019-01-04 20:25:38 · 213 阅读 · 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 if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2...原创 2019-01-05 13:49:39 · 695 阅读 · 1 评论 -
1078 Hashing (25 分)(hash表二次方探查法)
The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key%TSiz...原创 2019-01-05 17:55:06 · 284 阅读 · 0 评论 -
7-5 堆中的路径(最小堆)
将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数N和M(≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行给出M个下标。输出格式:对输入中给出的每个下标i,在一行中输出从H[i]到根结点...原创 2019-01-01 20:35:23 · 219 阅读 · 0 评论 -
7-18 Hashing - Hard Version (30 分)(哈希表,拓扑排序)
Given a hash table of size N, we can define a hash function H(x)=x%N. Suppose that the linear probing is used to solve collisions, we can easily obtain the status of the hash table with a given sequen...原创 2019-01-06 09:21:15 · 2465 阅读 · 0 评论 -
7-14 电话聊天狂人 (25 分)(map的使用)
给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人。输入格式:输入首先给出正整数N(≤105),为通话记录条数。随后N行,每行给出一条通话记录。简单起见,这里只列出拨出方和接收方的11位数字构成的手机号码,其中以空格分隔。输出格式:在一行中给出聊天狂人的手机号码及其通话次数,其间以空格分隔。如果这样的人不唯一,则输出狂人中最小的号码及其通话次数,并且附加给出并列狂人的...原创 2019-01-06 15:32:07 · 380 阅读 · 1 评论 -
7-15 QQ帐户的申请与登陆 (25 分)(map的使用,find,迭代器)
实现QQ新帐户申请和老帐户登陆的简化版功能。最大挑战是:据说现在的QQ号码已经有10位数了。输入格式:输入首先给出一个正整数N(≤105),随后给出N行指令。每行指令的格式为:“命令符(空格)QQ号码(空格)密码”。其中命令符为“N”(代表New)时表示要新申请一个QQ号,后面是新帐户的号码和密码;命令符为“L”(代表Login)时表示是老帐户登陆,后面是登陆信息。QQ号码为一个不...原创 2019-01-06 15:51:35 · 353 阅读 · 2 评论 -
7-8 File Transfer (25 分)(c++)(并查集)
We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possible to send a file from any computer ...原创 2019-01-02 11:45:04 · 1067 阅读 · 0 评论 -
1002 A+B for Polynomials (25 分)(模拟)
This time, you are supposed to find A+B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the informa...原创 2019-01-17 10:16:08 · 256 阅读 · 1 评论 -
7-6 列出连通集 (25 分)(bfs和dfs)
给定一个有N个顶点和E条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。输入格式:输入第1行给出2个整数N(0<N≤10)和E,分别是图的顶点数和边数。随后E行,每行给出一条边的两个端点。每行中的数字之间用1空格分隔。输出格式:按照"{ v1 v2 ... v...原创 2019-01-02 14:03:31 · 932 阅读 · 0 评论 -
1118 Birds in Forest (25 分)(并查集)
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 maxi...原创 2019-01-02 14:17:33 · 372 阅读 · 1 评论 -
1003 Emergency (25 分)(dijkstra)
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-01-17 11:28:33 · 133 阅读 · 0 评论 -
7-10 Saving James Bond - Easy Version (25 分)(dfs)(完全照着姥姥上课的思路)
This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land ...原创 2019-01-02 16:11:09 · 489 阅读 · 0 评论 -
1003 我要通过! (20 分)
“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“答案正确”大派送 —— 只要读入的字符串满足下列条件,系统就输出“答案正确”,否则输出“答案错误”。得到“答案正确”的条件是:字符串中必须仅有 P、 A、 T这三种字符,不可以包含其它字符; 任意形如 xPATx 的字符串都可以获得“答案正确”,其中 x 或者是空字符串,或者是仅由字母 A 组成的字符串; 如果 a...原创 2019-01-11 20:35:10 · 174 阅读 · 0 评论 -
7-7 六度空间 (30 分)(bfs)(c++简短高效解决)
“六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。图1 六度空间示意图“六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。但是数十年来,试图验证这个理论始终是许多社会学家努力追求的目标。然而由于...原创 2019-01-02 17:51:35 · 581 阅读 · 1 评论 -
1004 Counting Leaves (30 分)(dfs,bfs,树的层次遍历)
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one test case. Each case starts...原创 2019-01-17 16:21:58 · 243 阅读 · 0 评论 -
1005 Spell It Right (20 分)(字符串处理)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Eac...原创 2019-01-17 16:56:01 · 170 阅读 · 0 评论 -
7-8 哈利·波特的考试 (25 分)(Floyed)(c++描述,超详细注释,通俗易懂)
哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。现在哈利·波特的手里有一本教材,里面列出了所...原创 2019-01-02 21:43:58 · 970 阅读 · 2 评论 -
1006 Sign In and Sign Out (25 分)(查找元素)
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you...原创 2019-01-17 17:43:43 · 157 阅读 · 0 评论 -
1007 Maximum Subsequence Sum (25 分) [动态规划,最⼤连续子序列和]
Given a sequence of K integers { N1, N2, ..., NK}. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj} where 1≤i≤j≤K. The Maximum Subsequence is the continuous subse...原创 2019-01-17 18:20:57 · 246 阅读 · 0 评论 -
1008 Elevator (20 分)(水题)
The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 sec...原创 2019-01-17 20:26:59 · 366 阅读 · 0 评论 -
1009 Product of Polynomials (25 分)(模拟)
This time, you are supposed to find A×B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the informa...原创 2019-01-18 09:00:16 · 111 阅读 · 0 评论 -
1010 Radix (25 分)(二分查找,进制转换,字符串)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive inte...原创 2019-01-18 10:26:17 · 369 阅读 · 0 评论 -
7-9 旅游规划 (25 分)+dijkstra模板
有了一张自驾旅游路线图,你会知道城市间的高速公路长度、以及该公路要收取的过路费。现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径。如果有若干条路径都是最短的,那么需要输出最便宜的一条路径。输入格式:输入说明:输入数据的第1行给出4个正整数N、M、S、D,其中N(2≤N≤500)是城市的个数,顺便假设城市的编号为0~(N−1);M是高速公路的条数;S是出发地的城市编...原创 2019-01-03 13:41:34 · 223 阅读 · 0 评论 -
1004 成绩排名 (20 分)(结构体)
读入 n(>0)名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。输入格式:每个测试输入包含 1 个测试用例,格式为第 1 行:正整数 n第 2 行:第 1 个学生的姓名 学号 成绩第 3 行:第 2 个学生的姓名 学号 成绩 ... ... ...第 n+1 行:第 n 个学生的姓名 学号 成绩其中姓名和学号均为不超过 10 个字符的字...原创 2019-01-13 09:34:00 · 294 阅读 · 0 评论 -
1031 Hello World for U (20 分)(打印图形)
Given any string of N (≥5) characters, you are asked to form the characters into the shape of U. For example, helloworld can be printed as:h de ll rlowoThat is, the characters must be pri...原创 2019-01-23 18:09:50 · 132 阅读 · 0 评论 -
1012 The Best Rank (25 分)(排序,sort用法)
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...原创 2019-01-18 17:15:52 · 350 阅读 · 0 评论 -
1011 World Cup Betting (20 分)(水题)
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Si...原创 2019-01-18 17:23:06 · 326 阅读 · 0 评论 -
1029 旧键盘 (20 分)(string::npos和toupper函数)
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。输入格式:输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 _(代表空格)组成。题目保证 2 个字符串均非空。输出格式:按照发现顺序,在...原创 2019-01-13 20:57:43 · 178 阅读 · 0 评论 -
1013. Battle Over Cities (25) [图的遍历,统计连通分量量的个数,DFS]
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-01-18 19:29:44 · 231 阅读 · 0 评论 -
1015 Reversible Primes (20 分)(进制转换,素数)
A reversible prime in 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 pr...原创 2019-01-18 20:14:08 · 154 阅读 · 0 评论 -
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,...原创 2019-01-24 08:32:03 · 181 阅读 · 0 评论 -
1019 General Palindromic Number (20 分)(回文数)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers...原创 2019-01-18 20:42:04 · 234 阅读 · 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...原创 2019-01-24 11:20:15 · 215 阅读 · 0 评论