![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 64
qq_19272233
这个作者很懒,什么都没留下…
展开
-
集体照排序问题PAT A1109
问题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), with all the extra people原创 2021-08-29 19:12:43 · 161 阅读 · 0 评论 -
sscanf和sprintf的应用
问题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 number in [−1000,1000] a原创 2021-08-28 15:36:57 · 130 阅读 · 0 评论 -
图的BFS
问题分别用邻接矩阵和邻接表实现图的BFS算法邻接矩阵//邻接矩阵版int n,G[maxn][maxn];bool vis[maxn] = {false};void BFS(int u){ queue<int> q; q.push(u); inq[u] = true; while (!q.empty()){ int u = q.front(); q.pop(); for (int v = 0; v &l原创 2021-08-28 11:26:53 · 101 阅读 · 0 评论 -
图的DFS
问题分别用邻接表和邻接矩阵实现图的DFS算法邻接矩阵//邻接矩阵版本int n,G[maxn][maxn];bool vis[maxn] = {false};void DFS(int u,int depth){ //u为当前访问的顶点编号,depth为深度 vis[u] = true; //如果需要对 u 进行一些操作,可以在这里进行 //下面对所有从 u 出发能到达的顶点进行枚举 for (int v = 0; v < n; ++v) {原创 2021-08-28 11:00:21 · 178 阅读 · 0 评论 -
AOE网关键路径长度求解的实现
问题在一个有向无环图中,求解关键路径以及其长度。思路1.按拓扑排序和逆拓扑排序分别计算各顶点的(事件)的最早发生时间和最迟发生时间。2.用上面的结果计算各边的(活动)的最早开始时间和最迟开始时间。3.e[i->j] = l[i->j]的活动即为关键活动。代码#include <bits/stdc++.h>using namespace std;int n,m;const int maxn = 1010;struct node{ int v; in原创 2021-08-28 10:17:37 · 837 阅读 · 0 评论 -
求两个集合交集与并集的元素个数比例
问题1063 Set Similarity (25 分)Given two sets of integers, the similarity of the sets is defined to be Nc/Nt×100%, where Ncis the number of distinct common numbers shared by the two sets, and Ntis the total number of distinct numbers in the原创 2021-08-09 11:47:45 · 763 阅读 · 0 评论 -
分数相加问题
问题1081 Rational Sum (20 分)Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with a positive integer N (≤100), followed in the原创 2021-08-08 10:23:04 · 64 阅读 · 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 seconds to move the elevator up one原创 2021-08-07 16:33:32 · 91 阅读 · 0 评论 -
简单数学题
问题1104 Sum of Number Segments (20 分)Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3,原创 2021-08-07 16:14:11 · 120 阅读 · 0 评论 -
数字黑洞问题
问题1069 The Black Hole of Numbers (20 分)For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second nu原创 2021-08-07 00:07:33 · 93 阅读 · 0 评论 -
快速排序确定枢轴
问题1101 Quick Sort (25 分)There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the p原创 2021-08-06 23:17:51 · 527 阅读 · 0 评论 -
在字符串中特定字串的数量
问题1093 Count PAT’s (25 分)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 supp原创 2021-08-06 22:44:49 · 101 阅读 · 0 评论 -
寻找两个序列的中位数
问题1029 Median (25 分)Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is 15. The median of two sequences i原创 2021-08-06 22:19:01 · 185 阅读 · 0 评论 -
二分查找的简单应用
问题1085 Perfect Sequence (25 分)Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respectively.Now given a sequen原创 2021-08-05 23:55:01 · 58 阅读 · 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, 1, 3} we may apply t原创 2021-08-05 22:41:21 · 69 阅读 · 0 评论 -
乘积最大值(贪心思想)
问题给出两个集合,各选出n个元素,求乘积最大值、1037 Magic Coupon (25 分)The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product back!原创 2021-08-05 21:36:52 · 770 阅读 · 0 评论 -
贪心思想简单题(出售月饼)
问题1070 Mooncake (25 分)Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region’s culture. Now given the inventory amounts and原创 2021-08-05 17:32:18 · 100 阅读 · 0 评论 -
散列表空间换时间
问题1048 Find Coins (25 分)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, there was a special requireme原创 2021-08-05 17:08:07 · 124 阅读 · 0 评论 -
字符串的匹配
问题1050 String Subtraction (20 分)Given two strings S1and S2, S=S1−S2is defined to be the remaining string after taking all the characters in S2from S1. Your task is simply to calculate S1−S2for any given strings. However, i原创 2021-08-05 11:37:54 · 66 阅读 · 0 评论 -
散列表的运用
问题1092 To Buy or Not to Buy (20 分)Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in who原创 2021-08-05 10:43:28 · 46 阅读 · 0 评论 -
1012 The Best Rank 排序问题
问题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 - English. At the mean time, we原创 2021-08-03 14:31:42 · 75 阅读 · 0 评论 -
sort排序常见排名题
问题1062 Talent and Virtue (25 分)About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people’s talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a “sage(圣人)”原创 2021-08-03 12:12:45 · 276 阅读 · 0 评论 -
找字符串的最长后缀
问题1077 Kuchiguse (20 分)The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker’s personality. Such a preference is called “Kuchiguse” and is often exagge原创 2021-08-03 00:13:03 · 187 阅读 · 0 评论 -
密码易混淆字符替换去歧义问题
问题1035 Password (20 分)To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from原创 2021-08-02 22:28:39 · 132 阅读 · 0 评论 -
字符串的处理
问题1061 Dating (20 分)Sherlock Holmes received a note with some strange strings: Let’s date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange strings are actually referring to the cod原创 2021-08-02 18:35:52 · 54 阅读 · 0 评论 -
两个点分进制数的相加
问题1058 A+B in Hogwarts (20 分)If you are a fan of Harry Potter, you would know the world of magic has its own currency system – as Hagrid explained it to Harry, “Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it’s easy enough.” Y原创 2021-08-02 12:10:07 · 61 阅读 · 0 评论 -
巧解进制转换题
问题1027 Colors in Mars (20 分)People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the las原创 2021-08-02 11:47:16 · 81 阅读 · 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 printed in the original order,原创 2021-08-01 23:54:18 · 53 阅读 · 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.Although pal原创 2021-08-01 23:22:23 · 123 阅读 · 0 评论 -
简单的排序模拟题
问题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 case contains原创 2021-08-01 22:46:15 · 103 阅读 · 0 评论 -
sort排序问题
问题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 are supposed to fin原创 2021-08-01 20:20:37 · 197 阅读 · 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 information of a polynomial原创 2021-08-01 19:09:00 · 260 阅读 · 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 information of a polynomial:K原创 2021-08-01 17:18:49 · 104 阅读 · 0 评论 -
大整数的相加和大小判断
问题1065 A+B and C (64bit) (20 分)Given three integers A, B and C in [−263,263], you are supposed to tell whether A+B>C.Input Specification:The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow, each原创 2021-08-01 12:34:29 · 87 阅读 · 0 评论 -
简单的全源最短路径
问题1046 Shortest Distance (20 分)The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file contains one test case. For ea原创 2021-08-01 11:07:21 · 56 阅读 · 0 评论 -
扑克牌模拟算法题
问题1042 Shuffling Machine (20 分)Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers by performing inadequ原创 2021-08-01 10:21:01 · 159 阅读 · 0 评论 -
拓扑排序的实现(基于邻接表实现)
问题给出一个DAG,按事情的先后顺序给事件排序。思路利用队列,将所有入度为0的结点加入队列。队首元素出队,去除从该元素引出的边,相应的结点入度减一,如果减完后,结点入度为0,则加入队列。代码#include<bits/stdc++.h>using namespace std;const int maxn = 1000;vector<int> G[maxn];int n,m,inDegree[maxn];bool topologicalSort(){ i原创 2021-07-31 23:19:53 · 332 阅读 · 0 评论 -
prim算法解决亚历山大攻打恶魔大陆问题
问题求最小生成树的边权之和思路参考dijkstra算法的思路,更改d[]的含义,并且更新d[]的条件有一些不同。代码#include<bits/stdc++.h>using namespace std;const int maxn = 1000;const int INF = 1000000000;int d[maxn];int G[maxn][maxn];bool vis[maxn] = {false};int n,m;int prim(){ //默认0号为初原创 2021-07-31 22:26:48 · 78 阅读 · 0 评论 -
kruskal解决亚历山大攻打恶魔大陆问题
问题求连通图的最小生成树边权之和。思路将图的所有边按边权从小到大排序,从小到大枚举所有边。如果当前测试边的两个顶点位于两个不同的集合,则将该边和顶点加入到最小生成树中,并且累加其边权。当最小生成树的边数=定点数-1的时候,退出循环。此时的边权和即为所求。注意点1.此处使用结构体存储边的信息即可。包括两个顶点u,v。边权cost.2.会用到sort排序3.用到并查集和路径压缩的知识。代码#include <bits/stdc++.h>using namespace std;c原创 2021-07-31 21:59:13 · 47 阅读 · 0 评论 -
并查集的递推实现方法
问题判断两个元素是不是属于同一个集合,只需要查找他们的根元素,如果根元素相同则为同一个集合,否则为不同的集合。如果是不同的集合可以进行合并操作。为了提高查找效率,还可以采用路径压缩的方法。初始化int N;const int maxn = 1010;int father[maxn];//并查集的初始化void initUFS(){ for(int i=1;i<=N;++i) father[i] = i;}查找//查找int findFather(int原创 2021-07-31 21:32:07 · 97 阅读 · 0 评论