2019年12月7日PAT甲级满分题解与经验总结

PAT2019冬季甲级满分代码+占坑经验分享

  • 考题体验
    • A题 题目+题解
      • 题目
      • 题解
    • B题 题目+题解
      • 题目
      • 题解
    • C题 题目+题解
      • 题目
      • 题解
    • D题 题目+题解
      • 题目
      • 题解
  • 考场体验,ide经验提高效率

考题体验

第一次参加PAT,秋季没报上,集中准备一个月左右,刷了115道题买了两套模拟器花了20,参考柳神题目分类拷贝到印象笔记,记录每道题坑点和每天完成数.
我是倒着做的,后三道没什么问题卡住的,就是手速比较满,做完两道已经有人满人了,然后到第一题卡住了两个细节,这道题当时通过率只有0.04也看的出来,细节扣得比较细。
最后没什么问题交了还剩不到40分钟,跟大神还有大差距,总的来说冬季比较血赚,题比较常规,我怕的动态规划逻辑题数学题都没考,整挺好,第二天官网到付白嫖一个王者勋章。
2019年12月7日PAT甲级满分题解与经验总结_第1张图片
2019年12月7日PAT甲级满分题解与经验总结_第2张图片

第一次用markdown排版见谅

A题 题目+题解

题目

7-1 Good in C (20分)
题目详情
When your interviewer asks you to write “Hello World” using C, can you do as the following figure shows?2019年12月7日PAT甲级满分题解与经验总结_第3张图片
Input Specification:
Each input file contains one test case. For each case, the first part gives the 26 capital English letters A-Z, each in a 7×5 matrix of C’s and .'s. Then a sentence is given in a line, ended by a return. The sentence is formed by several words (no more than 10 continuous capital English letters each), and the words are separated by any characters other than capital English letters.It is guaranteed that there is at least one word given.
Output Specification:
For each word, print the matrix form of each of its letters in a line, and the letters must be separated by exactly one column of space. There must be no extra space at the beginning or the end of the word.Between two adjacent words, there must be a single empty line to separate them. There must be no extra line at the beginning or the end of the output.

Input Specification:

..C..
.C.C.
C...C
CCCCC
C...C
C...C
C...C
CCCC.
C...C
C...C
CCCC.
C...C
C...C
CCCC.
.CCC.
C...C
C....
C....
C....
C...C
.CCC.
CCCC.
C...C
C...C
C...C
C...C
C...C
CCCC.
CCCCC
C....
C....
CCCC.
C....
C....
CCCCC
CCCCC
C....
C....
CCCC.
C....
C....
C....
CCCC.
C...C
C....
C.CCC
C...C
C...C
CCCC.
C...C
C...C
C...C
CCCCC
C...C
C...C
C...C
CCCCC
..C..
..C..
..C..
..C..
..C..
CCCCC
CCCCC
....C
....C
....C
....C
C...C
.CCC.
C...C
C..C.
C.C..
CC...
C.C..
C..C.
C...C
C....
C....
C....
C....
C....
C....
CCCCC
C...C
C...C
CC.CC
C.C.C
C...C
C...C
C...C
C...C
C...C
CC..C
C.C.C
C..CC
C...C
C...C
.CCC.
C...C
C...C
C...C
C...C
C...C
.CCC.
CCCC.
C...C
C...C
CCCC.
C....
C....
C....
.CCC.
C...C
C...C
C...C
C.C.C
C..CC
.CCC.
CCCC.
C...C
CCCC.
CC...
C.C..
C..C.
C...C
.CCC.
C...C
C....
.CCC.
....C
C...C
.CCC.
CCCCC
..C..
..C..
..C..
..C..
..C..
..C..
C...C
C...C
C...C
C...C
C...C
C...C
.CCC.
C...C
C...C
C...C
C...C
C...C
.C.C.
..C..
C...C
C...C
C...C
C.C.C
CC.CC
C...C
C...C
C...C
C...C
.C.C.
..C..
.C.C.
C...C
C...C
C...C
C...C
.C.C.
..C..
..C..
..C..
..C..
CCCCC
....C
...C.
..C..
.C...
C....
CCCCC
HELLO~WORLD!

Sample Output:

C...C CCCCC C.... C.... .CCC.
C...C C.... C.... C.... C...C
C...C C.... C.... C.... C...C
CCCCC CCCC. C.... C.... C...C
C...C C.... C.... C.... C...C
C...C C.... C.... C.... C...C
C...C CCCCC CCCCC CCCCC .CCC.

C...C .CCC. CCCC. C.... CCCC.
C...C C...C C...C C.... C...C
C...C C...C CCCC. C.... C...C
C.C.C C...C CC... C.... C...C
CC.CC C...C C.C.. C.... C...C
C...C C...C C..C. C.... C...C
C...C .CCC. C...C CCCCC CCCC.

题解

#include
using namespace std;
struct node{
	string cp[7];
	node(){
		for(int i=0;i<7;i++){
			cp[i]=string("");
		}
	}
};
vector<node> CP(26);
string inst,tstr;
vector<string> wds;
vector<node> ans;
void printwd(string wd){
	if(wd.size()){
		node ans;
		int cpnum=wd[0]-'A';
		for(int j=0;j<7;j++)
			ans.cp[j]+=CP[cpnum].cp[j];
		for(int i=1;i<wd.size();i++){
			cpnum=wd[i]-'A';
			for(int j=0;j<7;j++){
				ans.cp[j]+=" ";
				ans.cp[j]+=CP[cpnum].cp[j];
			}
		}
		for(int i=0;i<6;i++)printf("%s\n",ans.cp[i].c_str());
		printf("%s",ans.cp[6].c_str());
	}
}
int main(){
	//ios::sync_with_stdio(0);
	//freopen(".//input.txt","r",stdin);
	for(int i=0;i<26;i++){
		for(int j=0;j<7;j++){
			cin>>tstr;
			CP[i].cp[j]=tstr;
		}
	}
	getchar();
	getline(cin,inst);
	if(inst.size()==0){
		return 0;
	}
	char cc=inst.back();
	if(cc>='A' && cc<='Z'){
		inst+=" ";
	}
	int s1=0,s2=0;
	for(int i=0;i<inst.size();i++){
		if(inst[i]>='A' && inst[i]<='Z'){
			s2++;
		}else{
			if(s2){
				tstr=inst.substr(s1,s2);
				wds.push_back(tstr);
			}
			s1=i+1;
			s2=0;
		}
	}
	if(wds.size()){
		printwd(wds[0]);
		for(int i=1;i<wds.size();i++){
			printf("\n\n");
			printwd(wds[i]);
		}
	}
	system("PAUSE");
	return 0;
}

A题坑点
1.写完,过一个测试点此时92. 测试调试为单词分割算法完全写错了,重写,此时98差一个测试点
2…看懂题目,要求大写字母,也就是大写字母外其他字符都识为分割符,写完看了两遍题才反应过来,交100分完成考试

B题 题目+题解

题目

7-1 Good in C (20分)
题目详情
Given a singly linked list L. Let us consider every K nodes as a block (if there are less than K nodes at the end of the list, the rest of the nodes are still considered as a block). Your job is to reverse all the blocks in L. For example, given L as 1→2→3→4→5→6→7→8 and K as 3, your output must be 7→8→4→5→6→1→2→3.
Input Specification:
Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (≤10^​5​​ ) which is the total number of nodes, and a positive K (≤N) which is the size of a block. The address of a node is a 5-digit nonnegative integer, and NULL is represented by −1.Then N lines follow, each describes a node in the format :Address Data Next where Address is the position of the node, Data is an integer, and Next is the position of the next node.
Output Specification:
For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input.

Input Specification:

00100 8 3
71120 7 88666
00000 4 99999
00100 1 12309
68237 6 71120
33218 3 00000
99999 5 68237
88666 8 -1
12309 2 33218

Sample Output:

71120 7 88666
88666 8 00000
00000 4 99999
99999 5 68237
68237 6 00100
00100 1 12309
12309 2 33218
33218 3 -1

题解

#include
using namespace std;
#define MAXN 100001
int sa,n,k,ai,di,nai;
vector<int> souce,ans;
struct node
{
	int a,d,na;
	node(){
		a=-1;d=-1;na=-1;
	}
	node(int aa,int dd,int nnaa){
		a=aa;d=dd;na=nnaa;
	}
}l[MAXN];
int main(){
	//freopen(".//input.txt","r",stdin);
	scanf("%d%d%d",&sa,&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&ai,&di,&nai);
		l[ai]=node(ai,di,nai);
	}
	for(int i=sa;i!=-1;i=l[i].na){
		souce.push_back(i);
	}
	int slen=souce.size();
	int snum=slen%k;
	int start;
	if(snum==0){
		start=(slen/k-1)*k;
	}else{
		start=slen/k*k;
	}
	for(int i=start;i>=0;i-=k){
		for(int j=i;j<slen && j<i+k ;j++){
			ans.push_back(souce[j]);
		}
	}
	if(n){
		for(int i=0;i<ans.size()-1;i++)
			printf("%05d %d %05d\n",ans[i],l[ans[i]].d,ans[i+1]);
		printf("%05d %d -1\n",ans.back(),l[ans.back()].d);
	}
	system("PAUSE");
	return 0;
}

B题注意
对于链表题,使用索引比较方便管理,答案保存索引即可

C题 题目+题解

题目

7-3 Summit (25分)
题目详情
2019年12月7日PAT甲级满分题解与经验总结_第4张图片
Output Specification:
2019年12月7日PAT甲级满分题解与经验总结_第5张图片.

Input Specification:

8 10
5 6
7 8
6 4
3 6
4 5
2 3
8 2
2 7
5 3
3 4
6
4 5 4 3 6
3 2 8 7
2 2 3
1 1
2 4 6
3 3 2 1

Sample Output:

Area 1 is OK.
Area 2 is OK.
Area 3 is OK.
Area 4 is OK.
Area 5 may invite more people, such as 3.
Area 6 needs help.

题解

#include
#define MAXN 201
using namespace std;
int n,m,ik,il,t1,t2,G[MAXN][MAXN];
vector<int> ar,v[MAXN];
void deal(int area){
	int flag=0,extra=-1;
	for(int i=0;i<ar.size();i++){
		for(int j=i+1;j<ar.size();j++){
			if(!G[ar[i]][ar[j]]){
				printf("Area %d needs help.\n",area);return;
			}
		}
	}
	map<int,int> mp;
	vector<int> ans;
	set<int> s;
	for(int i=0;i<ar.size();i++){
		mp[ar[i]]++;
		for(auto j:v[ar[i]])mp[j]++;
	}
	int maxnum=-1;
	for(auto i:mp){
		if(i.second>maxnum){
			ans.clear();
			maxnum=i.second;
			ans.push_back(i.first);
		}
		else if(i.second==maxnum)
			ans.push_back(i.first);
	}
	if(ans.size()==ar.size()){
		printf("Area %d is OK.\n",area);
	}else if(ans.size()>ar.size()){
		sort(ans.begin(),ans.end());
		for(auto i:ans){
			if(find(ar.begin(),ar.end(),i)==ar.end()){
				printf("Area %d may invite more people, such as %d.\n",area,i);
				return ;
			}
		}
	}
}
int main(){
	//freopen(".//input.txt","r",stdin);
	memset(G,0,sizeof(int)*MAXN*MAXN);
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&t1,&t2);
		G[t1][t2]=1;
		G[t2][t1]=1;
		v[t1].push_back(t2);
		v[t2].push_back(t1);
	}
	scanf("%d",&ik);
	for(int i=1;i<=ik;i++){
		scanf("%d",&il);
		ar.resize(il);
		for (int j = 0; j  < il; j ++)
			scanf("%d",&ar[j]);
		deal(i);
	}
	system("PAUSE");
	return 0;
}

C题坑点
题目:给定人,1.判断是否相符认识,2.找公同朋友是否完全
考虑需要完全仔细看题,做法计数最少共同好友和当前人数

D题 题目+题解

题目

7-4 Cartesian Tree (30分)
题目详情
2019年12月7日PAT甲级满分题解与经验总结_第6张图片
Output Specification:
For each test case, print in a line the level-order traversal sequence of the min-heap Cartesian tree. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the beginning or the end of the line…

Input Specification:

10
8 15 3 4 1 5 12 10 18 6

Sample Output:

1 3 5 8 4 6 15 10 12 18

题解

//#include
//#include
//#include
//#include
#include
using namespace std;
#define MAX 999999999
int n,tnum;
vector<int> v,ans;
typedef struct node{
	int d;
	node * cl,*cr;
	node(){
		d=-1;cl=NULL;cr=NULL;
	}
}*T;
T tree=NULL;
void build(T& t,int ll,int rr){
	if(ll>rr)return;
	t=(T)malloc(sizeof(node));
	t->cl=NULL;	t->cr=NULL;
	int minnum=MAX,minpos=-1;
	for(int i=ll;i<=rr;i++){
		if(v[i]<minnum){
			minnum=v[i];
			minpos=i;
		}
	}
	t->d=minnum;
	build(t->cl,ll,minpos-1);
	build(t->cr,minpos+1,rr);
}
void levelorder(T& t){
	if(t==NULL)return;
	queue<T> q;
	q.push(t);
	while(!q.empty()){
		T tt=q.front();
		q.pop();
		ans.push_back(tt->d);
		if(tt->cl)q.push(tt->cl);
		if(tt->cr)q.push(tt->cr);
	}
	return;
}
int main(){
	//freopen(".//input.txt","r",stdin);
	scanf("%d",&n);
	v.resize(n);
	for(int i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	build(tree,0,n-1);
	levelorder(tree);
	if(n){
		printf("%d",ans[0]);
		for(int i=1;i<ans.size();i++){
			printf(" %d",ans[i]);
		}
	}
	system("PAUSE");
	return 0;
}

D题坑点,
1.第一次考试,很坑,默认c编译器,没注意交了两次都全错,才反应过来,改成c++clang,一遍过
2.直接想到的方法建树,应该还有更优,但平时常规做法熟悉比较稳

考场体验,ide经验提高效率

平常练习用vscode方便创建文件夹直接编译
考前换到codeblock用了一会,容易假死我不太会用
咨询考场有vs2012,换到vs2012熟悉,
上考场
0.不着急开始考试,先设置好环境,创建好初始化文件
1.万能头文件从devc++库下bits文件拷到vs新建bits文件夹下
2.vs2012新建一个解决方案,然后内部创建4个项目ABCD表示做的题数,创建main.cpp和input.txt,编写c++模板,从文件读入数据方便调试。!!!注意交之前注释。测试可以正常使用

freopen(".//input.txt","r",stdin);

3.移除BCD(不是真的删除,写完A题,在添加B项目移除A项目),节省创建时间
4.关闭该死的安全杀毒软件某0
5.第一次考试,很坑,默认c编译器,没注意交了两次都全错,才反应过来,改成c++clang!!!

你可能感兴趣的:(PAT,入门,甲级)