七月份考了乙级75,被最后一题裁判机打到哭。九月份为了复习期末考试就没有报名甲级,10月多开始复习甲级,我的复习主要有两个方面:1.看算法笔记(神书,在我眼里比算法第4版还好)。2.刷穿甲级题库,我刷了144题,有些超纲的就不做了,类似tabble tennis、树型数组之类的。
我其实是个很胆小的人,看到通过很低我就不敢做了,还好这次第二题没看通过率,不然估计吓得直接做第三题了。我就有预感要考字符串,把字符串相关的问题都做了一遍,其实你只要做了坏键盘之类的那些题目,第二题是很简单的,暴力就能AC。
第四题看到题我想的只有怎么把这些方程式存下来,这里提一句(看完一道题目,大概建个模也就是写下大致思路很重要,事半功倍,不要有一点想法就去写,写了一半发现错了又浪费时间心态还炸裂)。这里两个测试点段错误,但是自己测试又没错,挺奇怪的,dalao们好像都用了dfs,可能我比较弱hhh。
考前心态转变了好几次,一开始只想考个70,后面做了那些树和图就莫名膨胀了,想考100了,又做了2020真题,md也太难了,又只想考70了。93说实话对于考前的我来说已经满意了,但是既然前三题都会做,最后一题又有思路,当然是想拿100的对吧,所以还是很遗憾。
至此我的pat之旅也就此结束了,不管网上说这个有用没用,我是的的确确学到东西了,建议像我一样学校不咋样的人都去考考,就算拿不到offer,那简历也不会被丢了对吧?
下面附上第4题垃圾代码
//用一个map记录是否有这种原材料
//strut里面分别存原材料和结果,记得要存直接变的结果1->1
//如果这个等式的原材料没有,就不能用这个等式,所有原材料用过了就不能再用
#include<cstdio>
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
using namespace std;
const int maxn = 100;
struct node{
vector<int> reactant;
int product;
}nodes[maxn];
unordered_map<int,int> exist;
bool cmp(node a, node b){
int len = min(a.reactant.size() , b.reactant.size());
for(int i = 0; i < len; i++){
if(a.reactant[i] != b.reactant[i]) return a.reactant[i] < b.reactant[i];
else return true;
}
}
int main(){
int n;
cin>>n;
int yuancailiao[25];
for(int i = 0; i < n; i++){
cin>>yuancailiao[i];
exist[yuancailiao[i]]++;
}
int m;
cin>>m;
int chanwu[15];
for(int i = 0; i < m; i++){
cin>>chanwu[i];
}
int k;
cin>>k;
string fangcheng[100] = {""};
for(int i = 0; i < k; i++){
for(int j = 0; ; j++){
cin>>fangcheng[j];
if(fangcheng[j] == "+" || fangcheng[j] == "->"){
nodes[i].reactant.push_back(stoi(fangcheng[j-1]));
}
char c = getchar();
if(c == '\n'){
nodes[i].product = stoi(fangcheng[j]);
break;
}
}
}
for(int i = k; i < k+n; i++){
nodes[i].reactant.push_back(yuancailiao[i-k]);
nodes[i].product = yuancailiao[i-k];
}
sort(nodes,nodes+k+n,cmp);
for(int i = 0; i < m; i++){
for(int j = 0; j < n+k; j++){
if(chanwu[i] == nodes[j].product){
bool flag = true;
for(int l = 0; l < nodes[j].reactant.size(); l++){
if(exist[nodes[j].reactant[l]] == 0){
flag = false;
break;
}
}
if(flag == true){
for(int l = 0; l < nodes[j].reactant.size(); l++){
exist[nodes[j].reactant[l]]--;
if(l!=0) cout<<" + ";
printf("%02d",nodes[j].reactant[l]);
}
printf(" -> %02d\n",nodes[j].product);
continue;
}
}
}
}
return 0;
}