PAT(甲级)2017年春季考试

A.Raffle for Weibo Followers

#include<bits/stdc++.h>
using namespace std; int m,n,s;
vector<string> person;
set<string> se;
vector<string> ans; int main(){
cin>>m>>n>>s;
for(int i=1;i<=m;i++){
string name;
cin>>name;
person.push_back(name);
}
int num = person.size();
// for(int i=0;i<num;i++) cout<<person[i]<<endl;
if(s > num) puts("Keep going...");
else{
int pos = s-1;
while(pos < num){
if(se.find(person[pos]) == se.end()){
se.insert(person[pos]);
// cout<<pos<<endl;
ans.push_back(person[pos]);
pos = pos + n;
}else{
pos++;
}
}
for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
} return 0;
}

B.Chain the Ropes优先队列

#include<bits/stdc++.h>
using namespace std; priority_queue<int,vector<int>,greater<int> > que; int n; int main(){
cin>>n;
for(int i=1;i<=n;i++){
int d;
cin>>d;
que.push(d);
}
while(que.size() != 1){
int fir = que.top();
que.pop();
int sec = que.top();
que.pop();
int thir = (fir + sec)/2;
que.push(thir);
}
cout<<que.top();
return 0;
}

C.Eulerian Path

还没做,统计度数来判断是不是欧拉回路,dfs判断是否连通图

#include<bits/stdc++.h>
using namespace std; const int maxn = 520;
int n,m;
vector<int> g[maxn];
int degree[maxn];
int odd = 0,even = 0;
bool vis[maxn];
int cnt = 0; void dfs(int x){
vis[x] = true;
cnt++;
for(int i=0;i<g[x].size();i++){
if(vis[g[x][i]] == false) dfs(g[x][i]);
}
} int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
degree[u]++;
degree[v]++;
}
for(int i=1;i<=n;i++){
if(degree[i]%2 == 0) even++;
else odd++;
}
dfs(1);
if(n == 0) {
puts("Non-Eulerian");
return 0;
}
if(n >= 1) cout<<degree[1];
for(int i=2;i<=n;i++) cout<<" "<<degree[i];
if(n >= 1) cout<<endl;
if(even == n && cnt == n) puts("Eulerian");
else if(odd == 2 && cnt == n) puts("Semi-Eulerian");
else puts("Non-Eulerian");
return 0;
}

D.ZigZagging on a Tree

二叉树,中序后序建树,输出Z字型层次遍历的结果

#include<bits/stdc++.h>
using namespace std; const int maxn = 50;
int n;
int post[maxn];
int in[maxn];
vector<int> ans[maxn]; struct node{
int v;
node *l;
node *r;
}; int maxDepth = 0; void dfs(node *root,int depth){
if(depth > maxDepth) maxDepth = depth;
ans[depth].push_back(root->v);
if(root->l) dfs(root->l,depth+1);
if(root->r) dfs(root->r,depth+1);
} node * build(int root,int il,int ir) {
if (il > ir) return NULL;
int pos = il;
while (pos <= ir && in[pos] != post[root])
pos++;
node* Root = new node;
Root->v = post[root];
Root->r = build(root-1, pos+1,ir );
Root->l = build(root-(ir-pos)-1 ,il,pos - 1);
return Root;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>in[i];
for(int i=1;i<=n;i++) cin>>post[i];
node *Root = new node();
Root = build(n,1,n);
dfs(Root,1);
cout<<ans[1][0];
for(int i=2;i<=maxDepth;i++){
if(i%2==0){
for(int j=0;j<ans[i].size();j++){
cout<<" "<<ans[i][j];
}
}else{
for(int j=ans[i].size()-1;j>=0;j--){
cout<<" "<<ans[i][j];
}
}
}
return 0;
}

PAT(甲级)2017年春季考试的更多相关文章

  1. PAT甲级满分攻略|记一次考试经历

    一次考试经历 今天是"大雪",很冷. 来到隔壁的学校考试,记得上一次来河中医是两年前大一刚开学吧,那天晚上印象比较深刻,6个室友骑车到处闲逛.当时还不会Hello world. 很 ...

  2. PAT(甲级)2017年秋季考试

    PAT(甲级)2017年秋季考试 D题红黑树待补21/30 大佬的代码,看着想哭,这才是艺术啊 A Cut Integer 模拟题 #include<bits/stdc++.h> usin ...

  3. 2021.9.12周六PAT甲级考试复盘与总结

    周六PAT甲级考试复盘与总结 先说结论:仍未步入"高手"行列:现在的学习节奏与方法是对的,有十万分的必要坚持下去. 题目 知识点 分数 T1 前缀和.二分 11 / 20 T2 排 ...

  4. pat甲级考试+pat1051+1056

    同上一篇博客: 贪心题目我已经刷了将近30道了,由于那几天考驾照就没写,以后有空的时候补过来吧,都在codeblock里 pat的题也刷了点,acwing 的题也刷了点,基本都攒下了.以后也会慢慢补过 ...

  5. PAT甲级满分有感

    时间轴: 2017年,数据结构加入了我的课程清单. 2018年12月,我从网易云课堂下载了数据结构的所有课程视频(学校里没有网,只能离线看),开始一刷.一刷只看了视频,基本没有做题,看到AVL树的时候 ...

  6. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  7. PAT甲级考前整理(2019年3月备考)之三,持续更新中.....

    PAT甲级考前整理一:https://www.cnblogs.com/jlyg/p/7525244.html,主要讲了131题的易错题及坑点 PAT甲级考前整理二:https://www.cnblog ...

  8. PAT甲级考前整理(2019年3月备考)之一

       转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...

  9. 2019秋季PAT甲级_备考总结

    2019 秋季 PAT 甲级 备考总结 在 2019/9/8 的 PAT 甲级考试中拿到了满分,考试题目的C++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...

随机推荐

  1. Java 中文数字转换为阿拉伯数字

    贴出代码,方便学习交流,稍后放出镜像问题的代码 package com.thunisoft.cail.utils; import com.sun.istack.internal.NotNull; im ...

  2. B/b.cpp:表达式化简,二分答案

    不知道能不能粘题面于是不粘了. 首先声明这道题可以怎么水过: 随机化几万次操作,取最优答案. 暴力O(n2log n)可过. 不想打正解的可以走了. emm然而我的应该是正解,O(n log n). ...

  3. Vue 2.x 3.x 配置项目开发环境跟线上环境

    先找到package.json  (这是nuxt版的vue 可能会跟一般vue不一样  当然总体上差不多的) "scripts": { "dev": " ...

  4. 基于cookie的用户登录状态管理

    cookie是什么 先来花5分钟看完这篇文章:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Cookies 看完上文,相信大家对cookie已经有 ...

  5. 46 Linden Street ACT I

    Execute me. My name is Richard Stewart. I’m a photographer. May I take a picture of you and your lit ...

  6. HTMLTestRunner加入logging输出

    使用HTMLTestRunner生成html的测试报告的时候,报告中只有console输出,logging的输出无法保存, 如果要在报告中加入每一个测试用例执行的logging信息,则需要改HTMLT ...

  7. 关于Eratosthenes筛子算法筛选小于n的素数的理解

    今天在学习Java核心技术第九章集合框架中的BitSet时,遇到了这个算法.Eratosthenes筛子算法时一个查找素数的方法,这并不是查找素数的最好方法,但是测试编译程序性能的一种流行的基准. 一 ...

  8. 深入理解计算机系统 第八章 异常控制流 part1

    本章主旨 第八章的目的是阐述清楚应用程序是如何与操作系统交互的(之前章节的学习是阐述应用程序是如何与硬件交互的) 异常控制流 异常控制流,即 ECF(exceptional contril flow) ...

  9. iOS蓝牙--CoreBluetooth基本使用

    蓝牙使用步骤: 1. 扫描外设 2. 连接外设 3. 连上外设后,获取指定外设的服务 4. 获取服务后,遍历服务的特征,得到可读,可写等特征,然后与中心管理者进行数据交互 附上代码 一:导入框架 #i ...

  10. 如何查看当前linux服务器是否支持虚拟化

    [root@localhost ~]# grep -E '(svm|vmx)' /proc/cpuinfo 或者: [root@localhost ~]# cat /proc/cpuinfo 找到fl ...