夜晚,总是个适合反思自己的时间,于是总结一下今天的PAT考试吧
今天,是浙大一年三度的PAT考试3月4日春季考试,本菜鸡也参加了甲级考试,其实网上说PAT甲级是越来越简单了,今天第一次参加的我也有所感查,所以我还是只考了62分的"高分段",但是真的考的很基础,涉及算法应该说是很浅很浅,由此还是显示了本人的基础只差和本人的英语水平之low。
进入正题,A题其实就是个简单的处理字符串的题,可是由于我的英语水平而误解题目的意思将其理解成每n个求第s个。。总之就是搞得好复杂,而且这题测试点也是真坑,给我过了3个测试点只有1个测试点不过,让我执着于此直至考试结束,而A题的正确题意是从第s个字符串为第一个winner开始,然后之后第n个为下一个winner,如果这个winner在之前被选过,则看之后第n+1个,然后从之后的第n+1再+n。。总之很水,代码来理解。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char jk[1005][25];
char hk[1005][25];
int u;
int check(char s[]){
int j, l, i;
for(i = 0; i < u; ++i){
j = 0;
while(s[j] == hk[i][j] && s[j] != '\0' && hk[i][j] != '\0'){
++j;
}
if(s[j] == '\0' && hk[i][j] == '\0') return 0;
}
return 1;
}
int main(){
int m, n, s, i;
cin >> m >> n >> s;
for(i = 1; i <= m; ++i)
cin >> jk[i];
if(s > m) printf("Keep going...\n");
else{
u = 0;
for(i = s; i <= m; i+=n){
while(!check(jk[i])) ++i;
strcpy(hk[u++], jk[i]);
}
if(u == 0) printf("Keep going...\n");
else{
for(i = 0; i < u; ++i)
printf("%s\n", hk[i]);
}
}
return 0;
}
B题更简单,题意得最后一个单词解救人生——halved,就是一个简单的排序之后,然后进行遍历计算的题。
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
using namespace std;
int jk[10005];
int main(){
int n, i, ans;
cin >> n;
for(i = 0; i < n; ++i){
cin >> jk[i];
}
sort(jk, jk+n);
ans = jk[0];
for(i = 1; i < n; ++i){
ans = (ans+jk[i])/2;
}
printf("%d\n", ans);
return 0;
}
C题考的是欧拉图和半欧拉图的概念= =,由于基础不牢,我用的dfs枚举边,然后有一个测试点超时。
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
using namespace std;
int f[505], ans[505];
int getF(int x){
if(x == f[x]) return x;
else{
f[x] = getF(f[x]);
return f[x];
}
}
void merge(int a, int b){
int fa, fb;
fa = getF(a), fb = getF(b);
if(fa != fb) f[fb] = fa;
}
int main(){
int n, m, i, a, b, k;
cin >> n >> m;
for(i = 1; i <= n; ++i){
f[i] = i;
ans[i] = 0;
}
for(i = 1; i <= m; ++i){
cin >> a >> b;
++ans[a];
++ans[b];
merge(a, b);
}
k = 0;
for(i = 1; i <= n; ++i){
if(i != n) printf("%d ", ans[i]);
if(ans[i] % 2 == 1) ++k;
}
if(n > 0) printf("%d\n", ans[n]);
for(i = 2; i <= n; ++i){
if(getF(i) != getF(1)) break;
}
if(i == n+1) {
if(k == 0) printf("Eulerian\n");
else if(k == 2) printf("Semi-Eulerian\n");
else printf("Non-Eulerian\n");
}
else printf("Non-Eulerian\n");
return 0;
}
D题和以往一样,和树有关的题,其实也不难,上午刚实现完avl树的代码,所以还是比较有把握,但是越有把握最后我也死的越惨,将树构建出来之后,层序遍历的改版在我仅剩的十多分钟内果真没有实现出来,于是30分完全流失,想想都心痛,唉。
这题遍历的时候利用了队列和栈的特性进行转换达到要求效果。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef struct node{
int value, index;
node *lson, *rson;
} *Lnode;
int jk[900];
int hk[900];
int getIndex(int e, int n);
Lnode insert(Lnode T, int id, int value);
void Visit(Lnode L);
int main(){
int i, n, id;
cin >> n;
Lnode T;
for(i = 1; i <= n; ++i) cin >> jk[i];
for(i = 1; i <= n; ++i) cin >> hk[i];
T = (Lnode)malloc(sizeof(node));
T->value = hk[n];
T->index = getIndex(hk[n], n);
T->lson = T->rson = NULL;
for(i = n-1; i >= 1; --i){
id = getIndex(hk[i], n);
T = insert(T, id, hk[i]);
}
Visit(T);
return 0;
}
int getIndex(int e, int n){
int i;
for(i = 1; i <= n; ++i)
if(e == jk[i]) return i;
}
Lnode insert(Lnode T, int id, int value){
if(T == NULL){
T = (Lnode)malloc(sizeof(node));
T->value = value;
T->index = id;
T->lson = T->rson = NULL;
}
else if(id > T->index){
T->rson = insert(T->rson, id, value);
}
else if(id < T->index){
T->lson = insert(T->lson, id, value);
}
return T;
}
void Visit(Lnode T){
queue<Lnode> q;
stack<Lnode> st;
int key = 0;
if(T == NULL) return;
q.push(T);
while(!q.empty() || !st.empty()){
while(!q.empty()){
Lnode x = q.front();
q.pop();
cout << x->value;
if(key){
if(x->lson != NULL) st.push(x->lson);
if(x->rson != NULL) st.push(x->rson);
}
else{
if(x->rson != NULL) st.push(x->rson);
if(x->lson != NULL) st.push(x->lson);
}
if(!q.empty() || !st.empty()) cout << " ";
else cout << endl;
}
while(!st.empty()){
q.push(st.top());
st.pop();
}
key ^= 1;
}
}
虽然本人做的如此水,但实际还是有很多得满分的,自己继续加油吧,向着前方潜行。
明天集训队组队赛,该睡觉了~