自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(58)
  • 收藏
  • 关注

原创 [C++] PAT 1048 Find Coins (25分)

Sample Input 1:8 151 2 8 7 2 4 11 15Sample Output 1:4 11Sample Input 2:7 141 8 7 2 4 11 15Sample Output 2:No Solution题解:1.此题直接两个数两个数遍历会超时2.设定一个cnt[]数组,下标表示数的大小,其值表示为该数出现的次数3.i从0开始遍历,跳过cnt[i]==0的数,记t=m-i,若cnt[t] >=1 找到匹配,输出结果代码:#i.

2020-09-02 11:26:26 2509

原创 [C++] PAT 1148 Werewolf - Simple Version (20分)

Sample Input 1:5-2+3-4+5+4Sample Output 1:1 4Sample Input 2:6+6+3+1-5-2+4Sample Output 2 (the solution is not unique):1 5Sample Input 3:5-2-3-4-5-1Sample Output 3:No Solution题解用v[]存储每个人说的话,让i从1~n,j从i+1~n,表示第i和j个人是.

2020-08-07 18:30:13 2805

原创 [C++] PAT 1006 Sign In and Sign Out (25分)

Sample Input:3CS301111 15:30:28 17:00:10SC3021234 08:00:00 11:25:25CS301133 21:45:00 21:58:40Sample Output:SC3021234 CS301133题解:将时间直接转化为数值#include <iostream>#include <string>#include <vector>using namespace std;int in_.

2020-08-02 23:59:21 2496

原创 [C++] PAT 1005 Spell It Right (20分)

Sample Input:12345Sample Output:one five题解:输入超过了整型的范围,所以使用字符串进行操作,对字符串进行累加存入整型变量中,注意输入为0的情况#include <iostream>#include <string>#include <vector>#include <cstring>#include <algorithm>using namespace std;string.

2020-08-02 23:46:51 2622

原创 python工程 打包exe生成图标 (failed to execute script main 错误)

如果打包python工程时遇见请参考之后我想自定义exe图标,其代码为pyinstaller --hidden-import=queue -w -F -i C:\Users\Desktop\logo.ico main.py-w 表示exe不包含控制台界面-F 表示打包后只生成单个exe文件,在dist目录下-i 表示添加图标,后面图标(ico)路径...

2020-07-21 10:07:23 3092

转载 python 多线程解决tkinter界面卡死问题

import tkinter as tkimport timeimport threading songs = ['爱情买卖','朋友','回家过年','好日子']movies = ['阿凡达','猩球崛起'] def music(songs): global text # 故意的,注意与movie的区别 for s in songs: text.insert(tk.END, "听歌曲:%s \t-- %s\n" %(s, time.ctime()))

2020-07-19 23:30:16 4163 1

原创 [C++] PAT 1096 Consecutive Factors (20分)

Sample Input:630Sample Output:3567题解:此题从2开始循环,一直连乘,如果连乘结果不是n的因子,跳出当前连乘,记录长度,和连乘开始的数字注意素数的处理#include <iostream>#include <cmath>using namespace std;int main(){ int n; cin >>n; int len = 0,first =0,maxn = sqrt(n)+1; for.

2020-07-19 22:17:56 2111

原创 [C++] PAT 1100 Mars Numbers (20分)

Sample Input:4295elo novtamSample Output:hel marmay11513题解:用map将字符串与文字进行对应,视情况输出#include <iostream>#include <string.h>#include <string>#include <unordered_map>using namespace std;string base_digit[13] = {"tre.

2020-07-19 21:40:35 2020

原创 [C++] PAT 1101 Quick Sort (25分)

Sample Input:51 3 2 4 5Sample Output:31 4 5题解:直接先对数组排序,如果排序后的元素i下标index在这里插入代码片保持不变,并且i大于原数组中i之前最大的元素max,则将i加入结果数组#include <iostream>#include <vector>#include <algorithm>using namespace std;struct node{ int index; lon.

2020-07-19 18:53:02 1917

原创 [C++] PAT 1104 Sum of Number Segments (20分)

Sample Input:40.1 0.2 0.3 0.4Sample Output:5.00题解:输入0.10.20.30.4取i从1开始,对于输入的第i个数,比如i=2,包含第2个数的组合从其两侧考虑,对于0.2,左边可以为0,可以为 0.1 ,有i==2个可能其右边可以为 0.3、0.4、0,有n-i+1总可能那么有i*(n-i+1)包含0.2的情况,让 ans += 0.2 * i * (n-i+1)由于double对于大规模运算会有精度问题,.

2020-07-19 17:07:42 1915

原创 [C++] PAT 1108 Finding Average (20分)

Sample Input 1:75 -3.2 aaa 9999 2.3.4 7.123 2.35Sample Output 1:ERROR: aaa is not a legal numberERROR: 9999 is not a legal numberERROR: 2.3.4 is not a legal numberERROR: 7.123 is not a legal numberThe average of 3 numbers is 1.38Sample Input .

2020-07-19 15:09:19 1918

原创 [C++] PAT 1110 Complete Binary Tree (25分)

Sample Input 1:97 8- -- -- -0 12 34 5- -- -Sample Output 1:YES 8Sample Input 2:8- -4 50 6- -2 3- 7- -- -Sample Output 2:NO 1题解:使用链表构建树结构,注意每个节点都有一个parent属性,最后根节是时直接判断parent为NULL的节点#include <iostream>#include <s.

2020-07-19 13:12:58 1908

原创 [C++] PAT Stucked Keyboard (20分)

Sample Input:3caseee1__thiiis_iiisss_a_teeeeeestSample Output:eicase1__this_isss_a_teest题解:用一个map<char,bool> 存储所有字符是不是坏键,考虑到出现k=3 aabbbaaa这种a不是坏键的情况用一个unordered_set<char>,存储所有不是坏键的字符之后遍历字符串,设立一个cnt,每次遍历到字符i,接着遍历i后k个字符j,如果j==i,cn.

2020-07-19 11:39:25 1917

原创 [C++] PAT 1117 Eddington Number (25分)

Sample Input:106 7 6 9 3 10 8 2 7 8Sample Output:6题解:此题要找到的是骑乘距离大于E的天数E中最大的那个E,需要在所有数据输入之后进行处理,比如输入数据天数12345678910距离67693108278第i天需要找出在所有天数中大于天数i的距离先对距离进行降序排序天数12345678910距离109887766.

2020-07-18 19:04:24 1976

原创 [C++] PAT 1126 Eulerian Path (25分)

Sample Input 1:7 125 71 21 32 32 43 45 27 66 34 56 45 6Sample Output 1:2 4 4 4 4 4 2EulerianSample Input 2:6 101 21 32 32 43 45 26 34 56 45 6Sample Output 2:2 4 4 4 3 3Semi-EulerianSample Input 3:5 81 22 55 44.

2020-07-18 16:38:42 1922

原创 [C++] PAT 1137 Final Grading (25分)

Sample Input:6 6 701234 880a1903 199ydjh2 200wehu8 300dx86w 220missing 400ydhfu77 99wehu8 55ydjh2 98dx86w 88a1903 8601234 39ydhfu77 88a1903 6601234 58wehu8 84ydjh2 82missing 99dx86w 81Sample Output:missing 400 -1 99 99ydjh2 200 9.

2020-07-18 15:45:37 1894

原创 [C++] PAT 1141 PAT Ranking of Institutions (25分)

Sample Input:10A57908 85 AuB57908 54 LanXA37487 60 auT28374 67 CMUT32486 24 hypuA66734 92 cmuB76378 71 AUA47780 45 lanxA72809 100 pkuA03274 45 hypuSample Output:51 cmu 192 21 au 192 33 pku 100 14 hypu 81 24 lanx 81 2题解:直接建立unordere.

2020-07-18 11:59:58 1922

原创 [C++] PAT 1144 The Missing Number (20分)

Sample Input:105 -25 9 6 1 3 4 2 5 17Sample Output:7题解:直接用map对每一个输入数字计数,之后从i=1开始遍历map,如果map[i] == 0,直接输出,停止循环在#include <iostream>#include <map>using namespace std;int n;map<int,int> mp;int main(){ cin >> n; .

2020-07-18 10:22:08 1915

原创 [C++] PAT 1152 Google Recruitment (20分)

Sample Input 1:20 523654987725541023819Sample Output 1:49877Sample Input 2:10 32468024680Sample Output 2:404题解:直接枚举所有k位子字符串,判断其是不是素数,0和1不是素数,需特殊处理#include <iostream>#include <string>using namespace std;int l,k;string .

2020-07-18 10:08:17 2216

原创 [C++] PAT 1154 Vertex Coloring (25分)

Sample Input:10 118 76 84 58 48 11 21 49 89 11 02 440 1 0 1 4 1 0 1 3 00 1 0 1 4 1 0 1 0 08 1 0 1 4 1 0 5 3 01 2 3 4 5 6 7 8 8 9Sample Output:4-coloringNo6-coloringNo题解:直接将所有边存储起来,另外用一个color[]存储每个节点的颜色,循环判断所有边的节点颜色是否相等#include.

2020-07-17 10:57:37 1917

原创 [C++] PAT 1147 Heaps (30分)

Sample Input:3 898 72 86 60 65 12 23 508 38 25 58 52 82 70 6010 28 15 12 34 9 8 56Sample Output:Max Heap50 60 65 72 12 23 86 98Min Heap60 58 52 38 82 70 25 8Not Heap56 12 34 28 9 8 15 10题解:由于是完全二叉树,直接采用访问数组下标的方式解决该题#include <iostream&.

2020-07-16 16:40:54 1893

原创 [C++] PAT 1151 LCA in a Binary Tree (30分)

Sample Input:6 87 2 3 4 6 5 1 85 3 7 2 6 4 8 12 68 17 912 -30 899 99Sample Output:LCA of 2 and 6 is 3.8 is an ancestor of 1.ERROR: 9 is not found.ERROR: 12 and -3 are not found.ERROR: 0 is not found.ERROR: 99 and 99 are not found.题解:.

2020-07-16 15:23:02 1916

原创 [C++] PAT 1143 Lowest Common Ancestor (30分)

Sample Input:6 86 3 1 2 5 4 8 72 58 71 912 -30 899 99Sample Output:LCA of 2 and 5 is 3.8 is an ancestor of 7.ERROR: 9 is not found.ERROR: 12 and -3 are not found.ERROR: 0 is not found.ERROR: 99 and 99 are not found.题解:利用中map自动排序的特性,对.

2020-07-16 11:49:09 1913

原创 [C++] PAT 1139 First Contact (30分)

Sample Input:10 18-2001 1001-2002 -20011004 1001-2004 -2001-2003 10051005 -20011001 -20031002 10011002 -2004-2004 10011003 -2002-2003 10031004 -2002-2001 -20031001 10031003 -20011002 -2001-2002 -200351001 -2001-2003 10011005 -2001.

2020-07-16 10:35:34 2179

原创 [C++] PAT 1135 Is It A Red-Black Tree (30分)

Sample Input:397 -2 1 5 -4 -11 8 14 -15911 -2 1 -7 5 -4 8 14 -15810 -7 5 -6 8 15 -11 17Sample Output:YesNoNo题解:本题考察红黑树,可以根据题目给出的数据直接构建二叉树,不需要去了解红黑树在构建过程中的左旋右旋以及其他规则,根据红黑树的定义:1.每个节点只能是红色或黑色2.根节点是黑色3.每个为NULL的叶子节点是黑色4.如果节点为红色,他的左右孩子均为黑色.

2020-07-14 16:29:46 1926

原创 [C++] PAT ZigZagging on a Tree (30分)

Sample Input:812 11 20 17 1 15 8 512 20 17 11 15 8 5 1Sample Output:1 11 5 8 17 12 20 15题解:1.先用中序-后序构建二叉树,2.设立stack<node*> odd,表示将奇数层结点的孩子结点放入odd中,先放右孩子,再放左孩子3.设立stack<node*> even,表示将偶数层结点的孩子结点放入even中,先放左孩子,再放右孩子4.根节为第1层(奇数层),将ro.

2020-07-14 11:03:13 1907

原创 [C++] PAT 1123 Is It a Complete AVL Tree (30分)

Sample Input 1:588 70 61 63 65Sample Output 1:70 63 88 61 65YESSample Input 2:888 70 61 96 120 90 65 68Sample Output 2:88 65 96 61 70 90 120 68NO题解:这里给出所有需要旋转的情况判断是否是完全二叉树,可以依据树的下标结构判断其输出的结点的下标是不是连续的,若是连续的下标,则该树是完全二叉树#include &lt.

2020-07-14 00:38:55 1926

原创 [C++] PAT 1119 Pre- and Post-order Traversals (30分)

Sample Input 1:71 2 3 4 6 7 52 6 7 4 5 3 1Sample Output 1:Yes2 1 6 4 7 3 5Sample Input 2:41 2 3 42 4 3 1Sample Output 2:No2 1 3 4题解:给出树的先序和后序遍历,这里先把树结构给出:可以发现在先序遍历中节点i的后一个节点必定是在其子树中,比如1的后一个节点2。同样,在后序遍历中节点i的前一个节点必定是在其子树中,比如1的前一个节.

2020-07-13 18:49:37 1961

原创 [C++] PAT 1115 Counting Nodes in a BST (30分)

Sample Input:925 30 42 16 20 20 35 -5 28Sample Output:2 + 4 = 6题解:1.直接采用结构体构建一棵BST,2.使用max_depth记录最大深度,使用num_depth[]记录每个深度有多少个节点,3.输出最后两个深度节点数及其和注意:如果在构建的时候就更新max_depth和num_depth[],无法通过全部测试点#include <iostream>using namespace std;st.

2020-07-12 11:28:20 1929

原创 [C++] PAT 1107 Social Clusters (30分)

Sample Input:83: 2 7 101: 42: 5 31: 41: 31: 44: 6 8 1 51: 4Sample Output:34 3 1题解:该题考察查并集,1.建立一个course[],course[t]代表第一个选择课程t的人2.建立father[],3.进行输入,对于每个人i,若其选择的course[t]==0,则将其赋值给course[t],否则修改其father,使其与course[t]的father相等4.再次遍历所有人,更新r.

2020-07-12 10:41:15 1985

原创 [C++] PAT Build A Binary Search Tree (30分)

Sample Input:91 62 3-1 -1-1 45 -1-1 -17 -1-1 8-1 -173 45 11 58 82 25 67 38 42Sample Output:58 25 82 11 38 67 45 73 42题解:在二叉搜索树中,对其进行中序遍历的结果是给出的数值序列从小到大的排列顺序,利用该该特性,以中序遍历方式构建二叉树的同时为节点赋值,最后再进行一次层次遍历即可#include <iostream>#include &l.

2020-07-11 21:51:17 1941

原创 [C++] PAT 1091 Acute Stroke (30分)

Sample Input:3 4 5 21 1 1 11 1 1 11 1 1 10 0 1 10 0 1 10 0 1 11 0 1 10 1 0 00 0 0 01 0 1 10 0 0 00 0 0 00 0 0 10 0 0 11 0 0 0Sample Output:26题解:此题直接采用BFS,对遍历过的点需要标记,避免再次遍历#include <iostream>#include <queue>using name.

2020-07-09 15:46:32 1915

原创 [C++] PAT All Roads Lead to Rome (30分)

Sample Input:6 7 HZHROM 100PKN 40GDN 55PRS 95BLN 80ROM GDN 1BLN ROM 1HZH PKN 1PRS ROM 2BLN HZH 2PKN GDN 1HZH PRS 1Sample Output:3 3 195 97HZH->PRS->ROM题解Dijkstra+DFS,在DFS中判断的时候先判断happness之后是cost#include <iostream>#inclu.

2020-07-09 12:30:47 1972

原创 [C++] PAT 1080 Graduate Admission (30分)

Sample Input:11 6 32 1 2 2 2 3100 100 0 1 260 60 2 3 5100 90 0 3 490 100 1 2 090 90 5 1 380 90 1 0 280 80 0 1 280 80 0 1 280 70 1 3 270 80 1 2 3100 100 0 2 4Sample Output:0 1035 6 72 81 4题解设立学生、学校结构体,学校结构体中设置last_grade和last_ge保存最后.

2020-07-09 11:00:02 1911

原创 [C++] PAT Gas Station (30分)

Sample Input 1:4 3 11 51 2 21 4 21 G1 41 G2 32 3 22 G2 13 4 23 G3 24 G1 3G2 G1 1G3 G2 2Sample Output 1:G12.0 3.3Sample Input 2:2 1 2 101 G1 92 G1 20Sample Output 2:No Solution题解最短路径问题,使用二维数组存储图结构,将站点拼接到房屋节点之后,使用Dijkstra求每个站点.

2020-07-08 15:49:37 1971

原创 [C++] PAT 1064 Complete Binary Search Tree (30分)

Sample Input:101 2 3 4 5 6 7 8 9 0Sample Output:6 3 8 1 5 7 9 0 2 4题解:在完全二叉搜索树中,其中序遍历必然是从小到大,可以直接对输入数据进行排序,直接得到其中序遍历;再模拟一次中序遍历,将数组填充数字后就可以得到以数组方式存储的完成二叉搜索树;直接输出数组即可得到其层次遍历#include <iostream>#include <algorithm>using namespace s.

2020-07-07 11:26:02 1911

原创 [C++] PAT 1045 Favorite Color Stripe (30分)

Sample Input:65 2 3 1 5 612 2 2 4 1 5 5 6 3 1 1 5 6Sample Output:7题解:该题运用动态规划,使用最长增长子序列(LIS)思想,在更新dp数组时需要判断当前颜色 i 和 i之前的颜色j,满足c_order[i] >= c_order[j]以及dp[j]+1 > dp[i],再更新dp[i]#include <iostream>using namespace std;int n,m,l;i.

2020-07-05 14:51:51 1968

原创 [C++] PAT 1038 Recover the Smallest Number (30分)

Sample Input:5 32 321 3214 0229 87Sample Output:22932132143287题解:参考了大佬的代码1.以字符串接收数据,2.之后对字符串数组进行排序,采用了贪心策略,3.最后将字符串数组进行拼接为字符串s,得到最小的数,4.注意是以非0开始,若s.length() == 0直接输出0#include <iostream>#include <string>#include <algorithm&gt.

2020-07-05 13:05:12 1911

原创 [C++] PAT 1022 Digital Library (30分)

Sample Input:31111111The Testing BookYue Chentest code debug sort keywordsZUCS Print20113333333Another Testing BookYue Chentest code sort keywordsZUCS Print220122222222The Testing BookCYLLkeywords debug bookZUCS Print2201161: The Tes.

2020-07-04 13:21:51 1981

原创 [C++] PAT 1018 Public Bike Management (30分)

Sample Input:10 3 3 56 7 00 1 10 2 10 3 31 3 12 3 1Sample Output:3 0->2->3 0题解:此题直接使用Djkstra+DFS,但要注意的是在经历每个点的时候就进行调整,而不是遍历完整个最短路径后进行调整,例:take表示从s0带出的自行车数量,re表示带回的自行车数量1.从s0到s1时,take=22.从s1到s2时,re=33.从s2到s3时,re=74.从s3到s4时,发现s4需要.

2020-07-04 11:29:44 6194

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除