自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 【PAT A1087】All Roads Lead to Rome

思路不多说好几题这种的了,现在应该差不多掌握了,一次就过了,很舒服。具体看注释。#include <cstdio>#include <string>#include <map>#include <algorithm>#include <iostream>#include <stack>using namesp...

2020-03-06 19:13:33 179

原创 【PAT A1072】Gas Station

思路这题当时看题看的一脸懵,说实话也不知道是我英语水平有问题还是他这题目语法有问题。其实题目就是让你给加油站选址,加油站尽量距离最近的人家尽可能远,否则就选择平均距离最小的,不多说直接上代码。#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#de...

2020-03-06 15:24:18 185

原创 【PAT A1018】Public Bike Management

题目太长就不抄了,这题得做个重点记号,比较典型。#include <cstdio>#include <vector>#include <stack>using namespace std;int cMax, N, Sp, M, cap[510] = {0}, G[510][510] = {0}, visited[510] = {0};int dis...

2020-03-05 19:58:31 187

原创 【PAT A1003】Emergency

#include <cstdio>#include <algorithm>using namespace std;int N, M, C1, C2, inf = 1000000000;int dis[510], G[510][510] = {0}, visited[510] = {0}, cnt[510], teams[510], total[510];in...

2020-03-04 21:23:32 130

原创 【PAT A1034】Head of a Gang

思路这里因为涉及到边的权重,而且存在双向边,因此我们最好将图看成有向图,而且用邻接矩阵来存储比较好。那么数组开多大?这取决于可能有多少点,因为点的name是3位char(A-Z),因此总共可能有26x26x26种,真的要这么多吗?仔细看可以发现边总共只有N条,即使每条边的首末节点互不相同,那么也只有2N个,所以我们实际上只用开1000x2+10(10是为了防止溢出)。另一个难点是点的name对...

2020-03-03 20:12:06 144

原创 【PAT A1021】Deepest Root

思路从每个节点依次构树,选最大者就好了(height数组记录每个节点所构树的高度),如果在构树的过程中有节点没有访问到,说明不连通,此时在没有访问的节点处再次dfs构树,依次下去即可得到连通分支个数。#include <cstdio>#include <vector>#include <algorithm>using namespace std;...

2020-03-03 14:29:32 145

原创 【PAT 1013】Battle over cities

思路其实这题实质上就是求去掉某个节点后,图的连通分量个数。这里去掉某个节点可以通过将visited置成1模拟实现,因为dfs不会去访问已访问的节点。我用的是邻接矩阵实现,空间复杂度比较大,可以用邻接表实现,btw并查集也是可以的(可以参考《算法笔记》)#include <cstdio>using namespace std;int N, M, K, G[1010][1010...

2020-03-03 10:06:30 104

原创 【PAT A1098】Insertion or Heap Sort

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, ...

2020-03-03 08:36:09 127

原创 算法伪代码写法

算法伪代码的主要部分1.算法名称Process 算法名 (参数列表) Function 算法名 (参数列表)2.输入输出Input:... Output:...3.指令序列书写规则:1)用Begin作为开始,End作为结束2)用“{”作为开始,用“}”作为结束如Begin 指令序列;End或者{ 指令序列;}伪代码设计细节1.条件...

2020-03-02 21:37:59 6193

原创 【PAT A1107】Social Cluster

Sample Input:83: 2 7 101: 42: 5 31: 41: 31: 44: 6 8 1 51: 4Sample Output:34 3 1思路从输入样例的第一个人开始,活动为2,7,10的人都可以借由1做朋友,也就是说,我们可以把2,7,10作为一个集合,不妨把每一行的第一个活动的根作为根,把后面的活动的根全都并到这个根上,并且每输入一行就把这...

2020-03-02 21:16:47 113

原创 【PAT A1053】Path of Equal Weight

这题题目有点长就不那啥了,是个不错的题。#include <cstdio>#include <vector>#include <algorithm>using namespace std;struct Node{ int weight; vector<int> childs;} Nodes[110];int N, M, S;...

2020-02-29 21:46:31 147

原创 【PAT A1102】Invert a Binary Tree

#include <cstdio>#include <queue>#include <iostream>using namespace std;struct Node{ int lchild = -1, rchild = -1;}Nodes[11];bool isNotRoot[11];int N;int invert(int roo...

2020-02-29 15:01:24 121

原创 【PAT A1086】 Tree Traversals Again

思路只要知道怎么靠输入序列构树就好了,可以发现如果当前push的前一个是push,那么当前push的数是前一个push的数的左子树,否则则是前一个pop的数的右子树。但是。。最后一个样例答案错误,有没有大佬可以指点一下,谢谢了!#include <cstdio>#include <stack>#include <iostream>using name...

2020-02-29 12:21:33 100

原创 【PAT A1091】Acute Stroke

思路广度优先遍历,感觉比较简单,不多说#include <cstdio>#include <queue>using namespace std;struct pixel{ int x, y, z;};int dirX[6] = {1, -1, 0, 0, 0, 0};int dirY[6] = {0, 0, 1, -1, 0, 0};int dir...

2020-02-28 20:44:05 130

原创 【PAT A1103】Integer Factorization

类dfs递归这个dfs最好有一个树在脑子里面,根节点不设任何东西,他的子节点为第一个位置可能的数,每个节点的子节点为不大于该节点的可能的数,节点的深度等于已经作为候选的数的个数#include <cstdio>#include <vector>#include <cmath>using namespace std;int N, K, P, ma...

2020-02-28 17:02:43 146

原创 【PAT A1040】Longest Symmetric String

Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you ...

2020-02-27 11:35:07 100

原创 【PAT A1045】Favorite Color Stripe

Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts...

2020-02-26 21:51:55 168

原创 【PAT A1007】Maximum Subsequence Sum

思路首先这是一个最优解问题,而且接下来我们还可以看到大问题可以分解为小问题,有了这两个条件,动态规划就没得跑了。假设已知n个连续序列的最大子序列,那么现在在后面追加一个数,求现在这个序列的最大子序列怎么求?可以这么想,现在的最大子序列可能包括追加的数,也可能不包括,如果不包括的话现在的最大子序列就是没有追加数之前的最大子序列,如果包含的话那么这个问题其实就变成了最大后缀的问题。好的现在来研究最...

2020-02-26 12:28:43 127

原创 【PAT A1068】Find More Coins

解法一(递归,最后一个样例超时)递归的方法基于以下思考:大问题分解为小问题–总额为m,从n个硬币中选,现在判断第n个硬币是否在最后符合条件的组合中,只需将问题分解成总额为m-coins[i],从n-1个硬币中选的子问题,子问题返回bool,若为true则说明选当前硬币,否则说明子问题无解,自然也不会选当前硬币。但有点不清楚为什么最后一个会超时,递归实例貌似没有重复的才对啊,希望有大佬能帮忙答疑...

2020-02-26 09:51:52 215

原创 【PAT A1074】Reversing Linked List

Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4,...

2020-02-07 20:50:15 220

原创 【PAT A1056】Mice and Rice

思路模拟比赛这个应该不难,书里面是用一个队列,不难发现比赛的过程有点类似树的层次遍历,但它是从下往上遍历;我是用优先队列整,毕竟他有着只关注优先级最高的特点,符合题意。令我稍有点头疼的是名次,刚开始我是先把所有人的名词都设成1,然后用一个vector存败者,每轮比赛过后吧这个vector里的人的名次都加1,这明显不符题意,就像注释里说的就算3个人并列第一,第四个人也是第四名而不是第二,那么接下...

2020-02-04 20:46:40 316

原创 【PAT A1051】Pop Sequence

Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the...

2020-02-01 12:28:33 188

原创 【PAT A1071】Speech Patterns

People often have a preference among synonyms of the same word. For example, some may prefer “the police”, while others may prefer “the cops”. Analyzing such patterns can help to narrow down a speaker...

2020-01-31 16:13:38 106

原创 【PAT A1100】 Mars Numbers

People on Mars count their numbers with base 13:Zero on Earth is called “tret” on Mars.The numbers 1 to 12 on Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, re...

2020-01-30 21:32:02 127

原创 matplotlib中文乱码解决

大家可参考链接

2020-01-22 13:27:41 77

原创 【PAT A1104】Sum of Number Segments

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...

2020-01-21 21:28:51 67

原创 【Pat A1069】The Black Hole of Numbers

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 takin...

2020-01-21 17:45:17 279

原创 【Pat A1044】Shopping in Mars

代码与思路#include <cstdio>using namespace std;#define INF 0x7fffffffint main(){ int num, cost, diamonds[100010]; scanf("%d%d", &num, &cost); for(int i = 0; i < num; i++) scanf...

2020-01-17 22:47:23 164 1

原创 【PAT A1085】Perfect Sequence

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, respecti...

2020-01-14 16:45:43 113

原创 【A1037】 Magic Coupon

Sample Input:41 2 4 -147 6 -2 -3Sample Output:43代码及思路:#include <cstdio>#include <algorithm>using namespace std;int main(){ int numCoupon, numProduct, Coupon[100010], Pr...

2020-01-10 21:11:02 96

原创 【PAT A1030】To Fill or Not to Fill

Sample Input 1:50 1300 12 86.00 12507.00 6007.00 1507.10 07.20 2007.50 4007.30 10006.85 300Sample Output 1:749.17Sample Input 2:50 1300 12 27.10 07.00 600Sample Output 2:The maxim...

2020-01-09 22:25:44 89

原创 【PAT B1020】月饼

题目描述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....

2020-01-07 14:38:45 268 1

原创 【PAT B1008】数组元素循环右移问题

【PAT B1008】数组元素循环右移问题解题思路:方法一:如上例,可先输出5,6也就是原数组的最后两位,再输出原数组的前四位,也就是1,2,3,4.或者在输入的时候就算出它在右移后的数组中的位置,直接存到对应位置即可。这个方法很简单,略。方法二:通过转置函数reverse来实现,即先把数组的后M%N位转置,再将数组的钱N-M%N位转置,最后再将整个数组转置一次即可达到目的。方法三:对循...

2020-01-06 11:21:11 414

原创 【PAT A1025】PAT Ranking

【PAT A1025】PAT Ranking问题描述Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in sever...

2020-01-03 18:02:34 85

原创 日期差值 【codeup 1928】

算法笔记刷题日记3.4 日期处理日期差值 [codeup 1928]3.4 日期处理日期差值 [codeup 1928]题目描述有两个日期,求两个日期之间的天数,如果两个日期是连续的我们规定他们之间的天数为两天。输入有多组数据,每组数据有两行,分别表示两个日期,形式为YYYYMMDD输出每组数据输出一行,即日期差值样例输入2013010120130105样例输出5...

2020-01-03 17:01:30 170

原创 Git&Github learning (持续更新)

Linux环境下搭建GitHub环境1.安装Gitsudo apt-get install git2.上GitHub官网注册账号(https://github.com)3.生成ssh key,用于连接GitHubssh-keygen -t rsa -C "your_email@youremail.com" //""中间的部分填自己的邮箱4.回到官网,在setting中选择

2017-12-30 15:51:10 328

原创 Leetcode(4):Median of Sorted Arrays

题目描述There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [

2017-06-20 15:39:45 204

原创 Leetcode(3):Longest Substring Without Repeating Characters

题目描述Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", w

2017-05-27 11:58:17 156

原创 MWeb 更新CSDN博客

首先自然是下载安装Mweb,这个不多说。直接切入正题。1.在偏好设置里面设置发布服务,直接上图: 选择Metaweblog API,然后填入博客网址(http://blog.csdn.net/用户名) 、账号、密码,api网址按上图填入,点击验证,如果在博客名称一栏自动生成了谁谁谁的博客就对了,否则就是没填对以上信息。2.发布博客 做了上面那一步就可以发布博客了,以

2017-05-22 16:18:04 2067 6

原创 HTML8 工作总结

HTML8 工作总结@(学习笔记)[HTML&CSS, Javascript]1. 文本阴影和盒子阴影其实text-shadow和box-shadow差别不大,其中重点要区别的是内嵌阴影和外阴影,以及掌握参数的含义就好了。这里重点说下内嵌阴影,它的格式如下:box-shadow: inset npx mpx kpx color其中n,m分别是阴影在水平方向和竖直方向的偏移,k

2017-05-22 15:54:08 1582

空空如也

空空如也

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

TA关注的人

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