自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 pat a 1133

感觉这道题主要是输出有点坑,思路还好,就是把小于0,大于k和在中间的数分成三组,然后在接起来#include <stdio.h>#include <vector>using namespace std;const int maxv=100010;struct Node{ int addr; int data; int next;}node[maxv];...

2020-01-31 20:31:17 106

原创 pat a 1126

用邻接矩阵写了一下,不过看到别人写的觉得可能还是邻接表好一些如果是测试点3过不去,那应该是此图不连通没有判断。#include <stdio.h>#include <cstring>using namespace std;const int maxv=510;int g[maxv][maxv];bool vis[maxv];int n,m;int cnt...

2020-01-30 22:23:50 140

原创 pat a 1025

贪心问题,魔塔玩多了就有经验了,要从两个魔法士中间走过去咱们最好血少点再过去,过去了再喝血打boss,美滋滋。#include <stdio.h>#include <algorithm>#include <vector>using namespace std;vector<double> list;int main(){ int n...

2020-01-30 20:02:33 88

原创 pat a 1124

这道题有3个测试点是以间隔三命题的,别问我怎么知道的…#include <stdio.h>#include <map>#include <iostream>#include <vector>using namespace std;const int maxv=1010;string list[maxv];map<string,...

2020-01-30 19:45:35 121

原创 pat a 1110

接着用指针写,和指针对抗到底#include <stdio.h>#include <cstring>using namespace std;const int maxv=25;struct Node{ int id; Node* left; Node* right;}node[maxv];int tonum(char a[]){ int sum=...

2020-01-29 15:09:44 164

原创 pat a 1106

#include <stdio.h>#include <vector>#include <cstring>#include <cmath>using namespace std;const int maxv=100010;const int inf=1000000000;bool vis[maxv];vector<int&gt...

2020-01-28 02:42:36 83

原创 pat a 1102

有了刚才1099的基础这个很快就能写出来啦不过需要注意的是如果是用%c输入的,那么一定要在适合的位置放getchar()来吸收掉\n,我在这里改了好久#include <stdio.h>#include <queue>#include <cctype>#include <cstring>#include <vector>us...

2020-01-28 00:34:28 124

原创 pat a 1100

尝试用map来写了一下,我感觉我这种写法还是有好多坑,改了好多遍。#include <stdio.h>#include <cctype>#include <iostream>#include <map>using namespace std;char num[14][5]={"tret","jan","feb","mar","apr",...

2020-01-27 19:09:35 99

原创 pat a 1099 (关于指针的一些问题)

我总是不怎么会用指针,正好借此题来试一下。对于符号->来说,前面跟的应该要是一个指针型变量,其余时候一般用.要想把一个变量在传参时变成一个指针型,可以在变量名前加&。至于定义一个指针嘛,用*,像stl里面的容器定义也可以定义成指针类型。具体可以看指针运算中的运算符&和*#include <stdio.h>#include <queue>#...

2020-01-27 17:55:11 98

原创 本地过编译 pat过不了的原因

我目前找到两种可能,一是使用了gets(),建议换成getline()二是使用了abs()函数时,给的头文件不是

2020-01-27 03:28:45 440

原创 关于error: cannot pass objects of non-trivially-copyable type ‘std::string’

具体可以看添加链接描述但一开始我看了还是不太明白到底什么时候用。后来想明白了,其实说白就是如果你要输出的字符串是string型,而不是字符数组型的,而你恰好又使用了printf来输出它,那么就要加上.c_str()。也就是说如果使用了cout来输出,就和平时一样了(测试了一下确实是这样)。这就是为什么说.c_str()是为了与c兼容。记录一下自己的问题...

2020-01-27 00:58:18 2364

原创 关于[Warning] pointer to a function used in arithmetic

[Warning] pointer to a function used in arithmetic [-Wpointer-arith]关于这个warning,直译是将指向函数的指针运用于计算中(译错勿怪)一开始我不明白,后来经仔细检查后发现我定义的一个函数,需要的变量是三个int,但我最后在使用函数时,本来应该是judge(x,y,z)的,结果我写成了judge[x][y][z],我想大概这...

2020-01-26 22:06:46 4559 3

原创 pat a 1079

一开始我所有测试点都是段错误,但在自己的电脑上能得到正确的答案。感觉自己数组并没有越界,那么我猜测可能是某个函数层数过多了,感觉dfs的那些递归都是必要的,那么只能在fill函数上了。一开始我对fee和lay的初始化都是用fill函数写的,修改过后就能通过了。所以我想对于数组初始为0的初始化,直接={0}会比较好。#include <stdio.h>#include <ve...

2020-01-24 23:50:26 140

原创 pat a 1077

记录一下,在一开始scanf的时候要把\n也读进去,不然就跳过了一次i了,就会出很诡异的结果。这是因为getline是默认以\n为结束符的,然后咱们一打回车,它就读了一行回车。还有学习了reverse函数(将字符串翻转,注意是begin()和end(),如果是int型数组是a,a+n的形式)和substr(截取i到j的字符串)#include <stdio.h>#include ...

2020-01-24 20:57:06 97

原创 pat a 1076

要理解题目,他给出的是谁关注了谁,而不是谁被谁关注,一开始我在这里出错。#include <stdio.h>#include <vector>#include <cstring>#include <queue>using namespace std;const int maxv=1010;int n,l,k;bool vis[max...

2020-01-24 12:34:00 142

原创 pat a 1073

感觉坑还挺多的,比如应该输出123我输出成123.或者又多输出一个符号,在修改的过程中代码越来越乱了#include <cstring>#include <iostream>using namespace std;int main(){ string num,temp=""; getline(cin,num); if(num[0]=='-'){ pri...

2020-01-23 18:46:23 135

原创 pat a 1072

贴一下我这回改bug的错误信息[Error] incompatible types in assignment of ‘const int’ to ‘int [1050]’这是由于在填写fill函数对二维数组赋值是本应是fill(gra[0],gra[0]+maxvmaxv,inf)写成了fill(gra,gra+maxvmaxv,inf)所以才会类型不匹配[Error] name look...

2020-01-23 17:26:51 350 2

原创 pat a 1071

需要注意的是isalnum的返回值如果是则返回非零,否则返回零。如果采用isalnum(i)==true的写法可能会得到错误的结果。另外记录一下用到的cctype里的函数isalpha()是不是字母isdigit()是不是数字isalnum()是不是字母数字tolower()转换成小写toupper()转换成大写#include <iostream>#include ...

2020-01-23 15:46:07 90

原创 pat a 1070

这道题一开始我计算总profit的时候是用一个while循环的,但是这样倒数第二个测试点会有段错误。我思考了 一下认为应该是提供的月饼全卖出去都无法满足那个amount,这样的话我的while循环就会一直进行下去,直到超过了list[1010],就产生了段错误,因此要想用while循环,还需要加一些限定条件。#include <stdio.h>#include <algori...

2020-01-23 14:10:20 141

原创 pat a 1063

本道题用set会比较方便,在这里放一下set的用法(1)insert()(2)find() st.find(*it) 找到返回其迭代器,否者返回st.end()(3)size()(4)clear():清空所有元素要注意set只能用迭代器访问,需要熟悉迭代器的定义法和初始化还有结束条件(具体参见题目)(*it)还有想在printf中输出%要写成%%在一开始的时候我是用一个set te...

2020-01-22 16:03:11 128

原创 pat a 1062

#include <stdio.h>#include <vector>#include <algorithm>using namespace std;struct people{ int id; int v; int t;};vector<people> sage;vector<people> noble;vec...

2020-01-22 14:58:29 99

原创 pat a 1061

如果有个别测试点错误,可以看看是否是字母的限定出了问题,例如对week来说应该是从A到G,对hh来说是0到9,A到N,特别是week,题目没有讲,但我们要会推测。我倒数第二个测试点就是因为week没有限定对出错了。#include <stdio.h>#include <cstring>#include <cctype>using namespace st...

2020-01-22 14:17:25 72

原创 pat a 1059

其实我觉得我这么写有毛病,long int能取到的素数应该没有我开的数组那么小,但是能够ac。以后再思考这个问题;如果第二个测试点答案错误,那么大概是n=1没有考虑,加进去就可以了另外对程序运行时间做一下记录,我使用了两个到maxv的for循环(取上限时间)当maxv=10^6时,运行时间为4ms左右;当maxv=10^7时,运行时间为30ms左右;当maxv=10^8时,运行时间为19...

2020-01-22 00:24:01 85

原创 pat a 1055

#include <stdio.h>#include <algorithm>#include <cstring>#include <vector>using namespace std;const int maxv=100010;struct person{ char name[10]; int age; int worth;}...

2020-01-21 21:05:46 75

原创 pat a 1054

一开始我用开数组的方式来记录超过半数的数,但是一直有一组数据超时。但是看了https://blog.csdn.net/phoenix_wei/article/details/79326124的算法后,觉得这个算法很厉害,起初我没有看懂,因此写在这里方便回忆。考虑到主元素必须超过半数,那么遇到一个数,对于等于它的数,计数值加一;不等于它的数,计数值减一;如果某个时刻计数值等于0了,那么说明读到当...

2020-01-21 20:13:17 155

原创 pat a 1053

我想自己最好再看看这道题的dfs函数,多模拟几次(一般这种记路径的题目push和pop总是成对出现的)#include <stdio.h>#include <algorithm>#include <vector>using namespace std;const int maxv=110;vector<int> tree[maxv];...

2020-01-21 18:22:35 171

原创 pat a 1049

思路参照https://blog.csdn.net/richenyunqi/article/details/97112648这篇博客讲的很详细#include <stdio.h>int main(){ int sum=0,n; int now,left,right; int ji=1; scanf("%d",&n); while(n/ji){ now=n/...

2020-01-21 00:14:22 142

原创 pat a 1050

一开始我怎么也对不了,但是又觉得和别人写的一样啊。后来发现对于bool flag[1000]={true};来说,只有flag[0]被赋值了true,其他的都是false。在赋值这方面要小心,以后还是培养用fill或者memset赋值的习惯吧。#include <stdio.h>#include <iostream>#include <cstring>...

2020-01-20 23:49:31 89

原创 pat a 1042

#include <stdio.h>char start[60];int st[60];char end[60];int en[60]; int temp[60];char whatis(int j){ if(j==1){ return 'S'; }else if(j==2){ return 'H'; }else if(j==3){ return 'C...

2020-01-19 23:47:16 107

原创 pat a 1041

#include <stdio.h>#include <vector>using namespace std;int flag[10010]={0};vector<int> num;int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ int temp; sca...

2020-01-19 22:59:25 70

原创 pat a 1040

在做这道题时发现本地可以过编译的结果在pat上过不了,查询后发现主要是因为pat不认gets()函数,可以将其替换成getline()。同时如果要使用getline,那么应该加上头文件这点可以具体参照这篇博客https://bbs.csdn.net/topics/392444813?page=1在做本体时第一得到17分,原因是一开始对偶数的处理不到位;再次提交得22分,看到两个错误测试点,我推...

2020-01-19 22:35:14 111

原创 pat a 1039

一开始最后一个测试点运行超时了,经检查发现是getid的值公式没有写对我猜测有的时候运行超时的错误也可以由段错误产生?#include <stdio.h>#include <vector>#include <algorithm>using namespace std; const int maxv=26*26*26*10+10;int geti...

2020-01-19 20:14:41 373

原创 pat a 1037

狂用vector和sort 将两组数据再分别分成正的一组(按从大到小排列),负的一组(从小到大排列),然后看两个数组大小,将两个数组相乘的结果累加即可#include <stdio.h>#include <vector>#include <algorithm>using namespace std;vector<long long int&gt...

2020-01-19 16:40:18 130

原创 pat a 1036

#include <stdio.h>#include <vector>#include <algorithm>using namespace std;struct person{ char name[15]; char gen; char id[15]; int gra;};vector<person> male;vecto...

2020-01-19 12:54:05 141

原创 pat a 1035

第二个测试点没有过的话,很有可能是在输出时直接复制了上面的话,然后仅修改了n注意account和accounts还有is和are#include <stdio.h>#include <vector>#include <cstring>using namespace std;struct person{ char name[20]; char p...

2020-01-19 11:38:54 98

原创 pat a 1030

还是很害怕图类的问题,开始尝试用邻接表写,可是越写越乱,最后还是换了回来。写在这里提醒自己,图类问题不要只定义,要赋初值啊,你在这种地方卡了多少回了…还有类似于–写成了++,在无向图赋两边值时随意复制过来导致出粗的问题让我改了好久bug…#include <stdio.h>#include <vector>#include <algorithm>us...

2020-01-18 21:02:54 141

原创 pat a1021

如果这道题得到了20分,有可能是因为在第一dfs时有多个最深路径,但我们只取了第一个,那么最终结果就会少掉我们漏掉的那些。本想用sort来排序,但感觉还是set好实现一些#include <stdio.h>#include <vector>#include <cstring>#include <set>using namespace st...

2020-01-18 13:25:23 229

原创 pat a 1029

看到通过率首先就有点吓到,不过用好vector就很简单了;看到别人代码,发现自己还是对这些常用函数不熟悉,知道.size()的话代码能更简洁些#include <stdio.h>#include <algorithm>#include <vector>using namespace std;vector<long int> line;...

2020-01-17 23:37:21 151

原创 pat a1025

#include <stdio.h>#include <algorithm>#include <cstring>using namespace std;struct student{ char id[15]; int score; int local; int lrank; int trank;}stu[30010];bool cmp(...

2020-01-17 22:11:21 66

原创 pat a1024

一开始有两个测试点无法通过,而且错误信息是段错误。注意到虽然一开始数字位数是十位,但考虑到步长为100以内,那么结果可能就很大了,因此大胆把数组写大写吧。#include <stdio.h>#include <cstring>using namespace std;char number[100];char renumber[100];int temp[100...

2020-01-17 19:58:59 181

空空如也

空空如也

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

TA关注的人

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