自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 PAT A1112 Stucked Keyboard (20分)

1. 题目给出一系列键盘输入,问是否有坏键。2. 代码使用一个非法字符加在str后面,就可以判断前后字母是否相等,很方便。设置两个布尔数组,一个假设是坏键,一个确定不是坏键。只要有一次正确输入就可以确定不是坏键。2.1 自己代码 (有点繁琐#include <iostream>#include <string>#include <vector>using namespace std;const int maxn = 1010;int main(

2020-07-27 23:22:56 92

原创 PAT A1111 Online Map (30分)

1. 题目给⼀张地图,两个结点中既有距离也有时间,有的单⾏有的双向,要求根据地图推荐两条路线:⼀条是最快到达路线,⼀条是最短距离的路线。2. 代码one-way 单行道分两次写DFS#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace std;const int MAXV = 510;const int INF

2020-07-26 23:47:22 95

原创 PAT A1110 Complete Binary Tree (25分)

1. 题目判断是否完全二叉树2. 代码因为index可能有两位数,不能使用char c,应该使用string或者char c[3]。建议使用string比较方便。但是不管哪种都要吸收换行符。根据是否有父节点判断是否是根结点,这点很常用1. 使用层序遍历#include <iostream>#include <string>#include <queue>using namespace std;const int maxn = 30;struct

2020-07-26 23:04:13 73

原创 PAT A1109 Group Photo (25分)

1. 题意照相位置排序,满足如下要求:每行人数必须为 N / K (四舍五入到最接近的整数),所有多余的人(如果有)都位于最后一行;后排的所有人员不得矮于前排的任何人员;在每一行中,最高的行位于中心位置(定义为该位置 (m/ 2 + 1 ),m 是该行中的总人数,除法结果必须向下取整;在每一行中,其他人必须以其身高不升序进入该行,交替地将他们的位置先移到最高人的右侧,然后再移至左侧(例如,假设五个人的身高分别为190、188, 186、175和170,最终阵型将是175、188、190、186和

2020-07-25 23:32:10 57

原创 PAT 1108 Finding Average (20分)

1. 题意 给出一组输入,存在非法输入,输出合法输入的平均值。2.代码测试点3注意当只有一个数时输出number。本来想用stod(str),但是输入非法时会抛出异常不能运行。使用atof(str.c_str())输入非法返回0,可能与合法输入混淆。还是柳神用的sscanf比较好#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main()

2020-07-25 23:06:32 64

原创 PATA1137 测试点4

1.题意给出一组学生成绩,将成绩合格的排序2.代码合格的成绩:Gp>=200 ,G>=60。注意不是Gfinal。输入时只需要判断Gp是否合法,其他照常输入。map<name,int> 存储学生name#include <iostream>#include <algorithm>#include <string>#include <map>#include <cmath>using names

2020-07-14 23:35:44 192

原创 PAT A1136 回文数

1. 题意给出1000位的数,判断是否是回文数。10次相加还不是回文数,输出。2. 代码最后一组数据超过long long,不能使用stoll(str)。开局判断是否是回文数,是的话直接输出 %s is a palindromic number.。算法笔记大整数运算。如果全程使用string,在大整数加法时要给出大小。否则不能使用str[i]=temp。加法完成后还要再str.resize(len)一次。#include <iostream>#include <alg

2020-07-14 16:33:10 86

原创 PAT A1133

题意 给出一个链表,要求负数值排在非负之前,[0,K]之间的数在前面,所有值原始顺序不变。代码分成三块分别存储结点,注意每块的结点数目都可能为0,所以会对每一块最后一个结点的next有影响。#include <iostream>#include <algorithm>#include <vector>using namespace std;const int maxn = 100010;struct node { int data; in

2020-07-13 23:24:12 118

原创 PAT A1132

题意给一个K位数,分成两个K/2位数,如果该K位数可以整除两个K/2位数的乘积,输出Yes代码使用stoi(str)很容易。注意除数为0的情况#include <iostream>#include <string>using namespace std;bool isDivided(string str){ int len=str.size(); string str1=str.substr(0,len/2); string str2=str.subst

2020-07-13 22:33:08 71

原创 PAT A1013 DFS使用邻接矩阵

只需要设置current_point表示当前删除的结点,置vis[current_point]=true即可。其他套模板#include <iostream>#include <algorithm>using namespace std;const int MAXV = 1010;const int INF = 0x3fffffff;int G[MAXV][MAXV];bool vis[MAXV] = {false};int n, m, K, current_p..

2020-07-13 15:32:53 81

原创 使用freopen输入无效的问题

定义std::freopen定义于头文件 cstdiostd::FILE* freopen( const char* filename, const char* mode, std::FILE* stream );使用绝对路径 freopen(R"(D:\CS\input.txt)","r",stdin); //输入重定向,输入数据将从D盘根目录下的in.txt文件中读取 freopen(R"(D:\CS\out.txt)","w",stdout); //输出重定向,输出数据将保存在

2020-07-13 15:08:57 2443

原创 PAT A1129 重载小于号快速解答

参考柳神代码题目要求从大到小排序,但是set是从小到大排序。本题重载小于号,换成适合本题的大的在前的判断方式,使用set的时候就符合本题的输出了。#include <iostream>#include <set>using namespace std;int book[50001]; //记录num出现的次数struct node { int index, cnt;};//set按从小到大排序,题目需要由大到小排序,重载小于号为大的在前的代码bool o

2020-07-12 23:26:21 113

原创 PAT A1053 使用vector存储结果

1. 关键代码简单重写了一下DFS,欢迎指正更简便的写法void DFS(int index, int sum) { if (Node[index].child.empty()) { //到达孩子结点 if (sum + Node[index].data == S) { temp.push_back(Node[index].data); ans[cnt++] = temp; temp.pop_back(); } return; }

2020-07-11 15:12:01 79

原创 PAT 第九章 树

一、 二叉树1. 常用函数struct node { int data; node *lchild, *rchild;};node *newNode(int v) { node *Node = new node; Node->data = v; Node->lchild = Node->rchild = nullptr; return Node;}void insert(node *&root, int x) { //如果要新建结点,即对二

2020-07-09 16:04:33 71

原创 PAT第八章 搜索专题

一、深度优先搜索DFS 要递归void DFS(int index,int sum,...)先写死胡同(有可能有多个)if(到达死胡同){ 更新结果; //如果不需要更新直接return return; //直接写return即可}再写岔道口DFS(index+1,sum+wegiht[index],...)DFS(index,sum,...)二、广度优先搜索BFS 队列模板void BFS(int s) { queue<int> q; q.pu

2020-07-07 16:35:39 71

原创 PAT 第七章 栈、队列和链表

一 栈二 队列三 链表1. 静态链表解题步骤定义静态链表struct node{ int address; int data; int next; int XXX; // 结点的某个性质};程序开始前对链表初始化。一般来说需要对链表的XXX属性进行初始化,将其定义为正常情况达不到的数字。 for (int i = 0; i < maxn; i++) { Node[i].XXX = maxn; }根据给出的首地址遍历得到整条链表。同时对

2020-07-07 14:54:35 81

原创 PAT常用函数

1. STL常用fill(begin,end,value)把数组或者容器中某一区间赋为相同的值。和memset()不同,这里可以是任意值。对二维数组的赋值,要使用fill(G[0],G[0]+MAXV*MAXV,value)。lower_bound(first,last,value) 返回有序数组或者容器中第一个大于等于value元素的位置。数组返回该位置的指针,容器返回该位置的迭代器。upper_bound(first,last,value) 返回第一个大于value的元素的位置。如果没

2020-07-06 16:10:49 406

原创 PAT 第六章 C++标准模板库

6.1 vector1.初始化vector<int> vt(n);vt.resize(n);初始化后可以使用scanf像数组一样进行输入,如不进行初始化使用scanf会返回错误。2.输入输出使用push_back()输入,pop_back()输出使用迭代器输出for (auto it = vt.begin(); it!=vt.end() ; it++) { printf("%d",*it); }只有vector和string可以使用vt.begin()

2020-07-06 15:45:17 99

原创 PAT A1126 测试点3错误

判断是否是连通图,如果没有判断导致测试点3错误even degree 偶数度#include <iostream>#include <vector>using namespace std;const int MAXV = 510;vector<int> Adj[MAXV], ans;bool vis[MAXV]={false};int cnt=0;void dfs(int index) { vis[index] = true; cnt++;

2020-07-04 16:57:48 179

原创 PAT A1124 测试点3问题

题目1124 Raffle for Weibo Followers (20分)John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo – that is, he would select winners from every N followers who forwarded his post, and give away gifts. Now

2020-07-04 14:57:20 263

原创 PAT A1104 测试点3问题

题目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, 0

2020-07-04 14:45:51 411 1

空空如也

空空如也

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

TA关注的人

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