PAT(甲级)2017年春季考试
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年春季考试的更多相关文章
- PAT甲级满分攻略|记一次考试经历
一次考试经历 今天是"大雪",很冷. 来到隔壁的学校考试,记得上一次来河中医是两年前大一刚开学吧,那天晚上印象比较深刻,6个室友骑车到处闲逛.当时还不会Hello world. 很 ...
- PAT(甲级)2017年秋季考试
PAT(甲级)2017年秋季考试 D题红黑树待补21/30 大佬的代码,看着想哭,这才是艺术啊 A Cut Integer 模拟题 #include<bits/stdc++.h> usin ...
- 2021.9.12周六PAT甲级考试复盘与总结
周六PAT甲级考试复盘与总结 先说结论:仍未步入"高手"行列:现在的学习节奏与方法是对的,有十万分的必要坚持下去. 题目 知识点 分数 T1 前缀和.二分 11 / 20 T2 排 ...
- pat甲级考试+pat1051+1056
同上一篇博客: 贪心题目我已经刷了将近30道了,由于那几天考驾照就没写,以后有空的时候补过来吧,都在codeblock里 pat的题也刷了点,acwing 的题也刷了点,基本都攒下了.以后也会慢慢补过 ...
- PAT甲级满分有感
时间轴: 2017年,数据结构加入了我的课程清单. 2018年12月,我从网易云课堂下载了数据结构的所有课程视频(学校里没有网,只能离线看),开始一刷.一刷只看了视频,基本没有做题,看到AVL树的时候 ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT甲级考前整理(2019年3月备考)之三,持续更新中.....
PAT甲级考前整理一:https://www.cnblogs.com/jlyg/p/7525244.html,主要讲了131题的易错题及坑点 PAT甲级考前整理二:https://www.cnblog ...
- PAT甲级考前整理(2019年3月备考)之一
转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...
- 2019秋季PAT甲级_备考总结
2019 秋季 PAT 甲级 备考总结 在 2019/9/8 的 PAT 甲级考试中拿到了满分,考试题目的C++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...
随机推荐
- 第六篇 视觉slam中的优化问题梳理及雅克比推导
优化问题定义以及求解 通用定义 解决问题的开始一定是定义清楚问题.这里引用g2o的定义. \[ \begin{aligned} \mathbf{F}(\mathbf{x})&=\sum_{k\ ...
- Golang的json包
encoding/json encoding/json是官方提供的标准json, 实现RFC 7159中定义的JSON编码和解码.使用的时候需要预定义struct,原理是通过reflection和in ...
- Vue躬行记(6)——内容分发
Vue提供了一种内容分发技术,可将父组件中的内容传递给子组件的模板,实现方式参照了Web组件规范草案. 一.插槽 Vue内置了一个<slot>元素,能作为插槽(slot)存在,而插槽内可包 ...
- 什么是"双活"
什么是"双活" 主备数据中心之间一般有热备.冷备.双活三种备份方式. 热备 热备的情况下,只有主数据中心承担用户的业务,此时备数据中心对主数据中心进行实时的备份,当主数据中心挂掉以 ...
- Python基本数据结构之字典
定义: {key1:value1,key2:value2} 1.键与值用冒号“:”分开: 2.项与项用逗号“,”分开: 示例: dic4={ 'name': 'xiaohu', 'age': 20, ...
- 小白学 Python(21):生成器基础
人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...
- day4-字符串专区
1.字符串 str (用''or“”表示) 字符串中每个组成部分为字符,python中只要是用引号引起来的都叫字符串 ---特征: 加法 n1 = "alex" n2 = &quo ...
- Jenkins集群下的pipeline实战
关于Jenkins集群 在<快速搭建Jenkins集群>一文中,我们借助docker快速搭建了Jenkins集群,今天就在这个集群环境中创建pipeline任务,体验Jenkins集群下的 ...
- 本地通知-UILocalNotification
第一步:创建本地推送 本地通知 UILocalNotification // 创建⼀一个本地推送 UILocalNotification * notification = [[UILocalNotif ...
- Anaconda 笔记
Anaconda笔记 conda 功能 管理版本的切换 安装其他的包 conda 创建python27环境 conda create --name python27 python=2.7 conda ...