2018PAT春季考试小结
- 暑假找工作,第一次考PAT,其实去年冬天就想试试水的,但年底开题+开组会,最终还是没报名。等到快放寒假了加上一个春节的时间,想着再家里看能刷刷题么,结果无数次的实验还是证明了一件事,那就是对于我,在家里休想学习。过完春节3月6号到了学校,其实离18号考试也就只剩12天了,我的基础,也只是之前在leetcode上刷过200题而已,然而在PAT官网上只刷了14道,每一道都花了很长时间才过的,慢慢的熟悉了写输入输出,却因为Java这门语言实在太慢,几乎每次都超时,可以得到的分都得不到,都怀疑还要不要坚持考PAT了。可是简历上依然是一片空白!既然选择了远方就不要放弃吧,主要是特别想看看自己的算法水平究竟怎么样,所以开学了就报名了,于是就天天都在牛客网上和官网上刷PAT真题了,真的有时候会怀疑,为什么大一的时候没有好好学c语言,因为自己java比较熟练,所以一直不敢转到自己只有一点点老底的c,况且时间也所剩无几了,只有扛着java硬上了。陆陆续续的刷过了不少题,我发现在努力让java程序跑的更快的路上我还是学到了不少东西的,比如ACM大神的BufferedReader读输入,StringTokenizer替换spilite等,但如果题目故意有个大数据测试点那么你还是认命吧,超时就是超时。前前后后刷过了60多题吧,主要是一直参考柳婼 の blog她的博客,每一道题她都有解答和分析,而且都基本是我见过的最好的方法,所以真的学习了不少!只恨自己吸收的太慢,理解的不够。
离考试还有5天的时候开始做模拟套题,在规定的考试时间计时答题,第一次85,第二次97分,第三次57,第四次和第五次都是做到一半就崩溃了,真的不会啊。后来都开始安慰自己,8月再考一次吧,这次就当试手了,做到怀疑人生大概如此吧,就是除了算法题做什么都可以,哪怕是让我去看论文?考试前两天不写代码了,主要是看看其他我没刷过的题型,然后看看别人的解答,我发现自己对于dijkstra算法还是很不熟悉,就多看了些图的题,真的难的题,你看了,理解了,你基本还是会在心里说,如果遇到这题,我真的不会做,深搜吧,大不了超时。考试当天说下午1点半,为了怕困,我选择睡一上午不起来,真的下午我会习惯性困啊!提早2小时到了北工大,正好是吃饭的点,就和一陌生哥们借了下卡吃了个饭,完了就去计算中心等着了。
因为去太早了,那里的老师说可以在一楼的机房自由上机,我进去看了下,打开任何一个系统都没有eclipse,我当时就慌了,心想考场不会也是这样吧,不过还好有netbeans,不过我也从没用过啊,于是赶紧网上百度下netbeans里怎么跑java项目,不过后来才发现我多虑了。
1点半准时开考,1点28才摸到我的机子,心想下一次我一定要抢到一个考前的位置早点进机房,前面没带身份证的哥们你太墨迹了。进机房二话不说打开eclipse写我的读输入类Read用它替代Sacnner,这个会耗费我4分钟左右。但对界面不太熟悉,其实只要在当前界面点击进入考题就可以的,但我刚进去没听到这一句,于是最后过了好几分钟才问明白老师怎么进入题目页面。
- 第一道题是look and say,简单题,我花了20分钟才搞定,对机房的键盘,椅子等太不熟悉,写代码也一直出错,状态还在调整。这里最需要提出来的是,考试时的OJ界面,提交了代码后显示正在测评,可这个界面停在这里就不动了,我去,在平时官网上刷题时体检完很快会弹出测评结果的啊,而且测评只要5ms不是?我当时一边苦苦等待它自动跳转,一边招手找老师看是不是电脑的问题,可是老师不理我,电脑也不理我,于是我就想右上角有个刷新点一下看看吧,一点才发现全正确,可惜这耗费了我快2分钟,简直笨死了我,后面一美女都估计都在嘲笑我了吧,哎。接下来做到第二题,PAT成绩排名打印,我这才进入状态,题目很简单,一次就过了几个点,剩下的两个点超时,我想100分是肯定是拿不到了,做完第二题3小时已经花了1个小时了,第三题是图论题,我感觉不难,但一提交中间两个点错了,我想待会再来查吧,于是就继续做,此时才过1个半小时,最后一个是求BST树中任何两个节点的最小公共父节点,并不难啊,很快就写完代码过了算例,一看果然后面2个点超时,还有个点出了错。此时还有一个小时!我心想还有这么多时间,那可得仔细好好查查,结果后面一个小时都在找错,却只把第四道题的2分的错找出来了,第三题的错始终找不到,而超时的我又无能为力,于是考试结束我才离开,总觉得很不甘心,那个错了的两个点有6分,如果我换成c,那么这次成绩就是94分了,比77分好看的多了啊,8月份再来考一次啊!如果到时候我还有这份执念的话….总之这就是第一次PAT考试经历,算对得起这10多天的刷题经历了吧。
- 最后再重申一句,考PAT不要用Java!!!
- 附上考完后登录邮箱传回来的我的源码:
No-1
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
Read.init(System.in);
String s = Read.next();
int n = Read.nextInt();
char c;
StringBuilder sb = new StringBuilder();
int num;
for (int i = 0; i < n - 1; i++) {
c = s.charAt(0);
num = 1;
sb = new StringBuilder();
for (int j = 1; j < s.length(); j++) {
if (s.charAt(j) != c) {
sb.append(c);
sb.append(num);
c = s.charAt(j);
num = 1;
} else {
num++;
}
}
sb.append(c);
sb.append(num);
s = sb.toString();
}
System.out.println(s);
}
}
class Read {
static BufferedReader br;
static StringTokenizer st;
static void init(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
static String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
}
No-2
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
Read.init(System.in);
int n = Read.nextInt();
String id, school;
int score;
Map<String, Node> map = new HashMap<>();
for (int i = 0; i < n; i++) {
id = Read.next();
score = Read.nextInt();
school = Read.next().toLowerCase();
if (map.containsKey(school)) {
Node node = map.get(school);
node.num++;
if (id.charAt(0) == 'A') {
node.a += score;
} else if (id.charAt(0) == 'B') {
node.b += score;
} else
node.t += score;
} else {
Node node = new Node(school);
if (id.charAt(0) == 'A') {
node.a += score;
} else if (id.charAt(0) == 'B') {
node.b += score;
} else
node.t += score;
map.put(school, node);
}
}
List<Node> list = new ArrayList<>(map.values());
Node pre = null;
for (int i = 0; i < list.size(); i++) {
Node node = list.get(i);
node.wei = (int) (node.b / 1.5 + node.a + node.t * 1.5);
}
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
Node node = list.get(i);
if (i == 0) {
node.ran = 1;
pre = node;
} else if (node.wei == pre.wei) {
node.ran = pre.ran;
} else {
node.ran = i + 1;
pre = node;
}
}
System.out.println(list.size());
for (int i = 0; i < list.size(); i++) {
Node temp = list.get(i);
System.out.println(temp.ran + " " + temp.name + " " + temp.wei + " " + temp.num);
}
}
static class Node implements Comparable<Node> {
String name;
int wei, num, ran;
int a, b, t;
Node(String n) {
name = n;
num = 1;
}
@Override
public int compareTo(Node node) {
if (wei != node.wei)
return node.wei - wei;
else if (num != node.num)
return num - node.num;
else
return name.compareTo(node.name);
}
}
}
class Read {
static BufferedReader br;
static StringTokenizer st;
static void init(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
static String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
}
No-3
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
public class Main {
static boolean[][] edg = new boolean[205][205];
static int N;
public static void main(String[] args) throws IOException {
Read.init(System.in);
int n = Read.nextInt(), ne = Read.nextInt();
N = n;
for (int i = 0; i < ne; i++) {
int u = Read.nextInt(), v = Read.nextInt();
edg[u][v] = true;
edg[v][u] = true;
}
int k = Read.nextInt();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < k; i++) {
int num = Read.nextInt();
list.clear();
for (int j = 0; j < num; j++) {
list.add(Read.nextInt());
}
int r = check(list);
if (r == 1) {
System.out.println("Yes");
} else if (r == -1) {
System.out.println("Not a Clique");
} else if (r == 2) {
System.out.println("Not Maximal");
}
}
}
private static int check(List<Integer> list) {
for (int i = 0; i < list.size() - 1; i++) {
int u = list.get(i);
for (int j = i + 1; j < list.size(); j++) {
if (!edg[u][list.get(j)])
return -1;
}
}
Set<Integer> set = new HashSet<>(list);
for (int i = 1; i <= N; i++) {
if (!set.contains(i)) {
boolean f = true;
for (int j = 0; j < list.size(); j++) {
if (!edg[i][list.get(j)]) {
f = false;
break;
}
}
if (f)
return 2;
}
}
return 1;
}
}
class Read {
static BufferedReader br;
static StringTokenizer st;
static void init(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
static String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
}
No-4
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static boolean f = false;
public static void main(String[] args) throws IOException {
Read.init(System.in);
int M = Read.nextInt(), N = Read.nextInt();
Node head = null;
for (int i = 0; i < N; i++) {
int temp = Read.nextInt();
head = insert(head, temp);
}
for (int i = 0; i < M; i++) {
int u = Read.nextInt(), v = Read.nextInt();
int k1 = find(head, u), k2 = find(head, v);
if (k1 == -1 || k2 == -1) {
if (k1 == -1 && k2 == -1) {
System.out.printf("ERROR: %d and %d are not found.\n", u, v);
} else if (k1 == -1) {
System.out.printf("ERROR: %d is not found.\n", u);
} else {
System.out.printf("ERROR: %d is not found.\n", v);
}
} else {
if (u == v) {
System.out.printf("%d is an ancestor of %d.\n", u, v);
continue;
} else if (u > v) {
int temp = u;
u = v;
v = temp;
f = true;
}
help(head, u, v);
}
}
}
private static int find(Node head, int u) {
if (head == null)
return -1;
if (head.val == u)
return 1;
else if (head.val > u)
return find(head.left, u);
else
return find(head.right, u);
}
private static void help(Node head, int u, int v) {
if (head == null)
return;
if (head.val == u || head.val == v) {
if (head.val == u) {
System.out.printf("%d is an ancestor of %d.\n", u, v);
} else
System.out.printf("%d is an ancestor of %d.\n", v, u);
return;
} else if (head.val < u) {
help(head.right, u, v);
} else if (head.val > v) {
help(head.left, u, v);
} else {
if (f)
System.out.printf("LCA of %d and %d is %d.\n", v, u, head.val);
else
System.out.printf("LCA of %d and %d is %d.\n", u, v, head.val);
return;
}
}
private static Node insert(Node head, int temp) {
if (head == null)
return new Node(temp);
if (temp > head.val) {
head.right = insert(head.right, temp);
} else
head.left = insert(head.left, temp);
return head;
}
static class Node {
int val;
Node left, right;
Node(int val) {
this.val = val;
}
}
}
class Read {
static BufferedReader br;
static StringTokenizer st;
static void init(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = new StringTokenizer("");
}
static String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
}
接下来好好休息几天该搞科研了…比较是马上要毕业了啊(哭…),不过还是要把c语言好好看看了!!