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. SSH隧道的使用

    合作部门提供的 redis 集群,kafka 集群,限制条件:无 vpn,仅能通过特定跳板机(无 root 权限)连接调试开发. 想要实现:本地开发连接其 redis 集群,kafka 集群进行开发调 ...

  2. [2018-06-27] virtualenv

    在开发Python应用程序的时候,系统安装的Python只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目录下. 如果我们要同时开发多个应用程序,那这些 ...

  3. 使用VM虚拟机安装Linux系统详细流程

    最近新换了个电脑,所以需要重新安装虚拟机和Linux系统,话不多说,看流程吧 1.安装vm,这个就不说了,打开VM 2.点击安装虚拟机 3.选择自定义安装 4.选择稍后安装 5.选择要安装的系统 6. ...

  4. windows系统一台电脑先后添加多个git账号

    概述 电脑上已经配置了github的ssh连接.现在又有一个不同的git账户,也就是要在一台电脑上配置两个git账号. 下面记录一下我配置的方法. 一.取消git全局配置 之前配置github的时候, ...

  5. 关于发送邮件,错误“命令顺序不正确。 服务器响应为:Error: need EHLO and AUTH first !”问题

    最近做了一个小程序,通过QQ邮箱服务器发送邮件, 代码写完后,运行调试,出现“命令顺序不正确. 服务器响应为:Error: need EHLO and AUTH first !”的问题, 上网查询发现 ...

  6. Mybatis中多表关联时,怎么利用association优雅写resultMap来映射vo

    前言 有好一阵没碰mybatis了,这次的项目基于性能考虑,选了mybatis,写着写着,发现有下面的需求,比如两表联查,取其中各一部分字段,怎么更方便地用vo来接,这里犯了难: 我想的是,因为这个s ...

  7. mysql select自增变量(包括读取当前第几行)

    mysql select自增变量(包括读取当前第几行) SET @rownum =0;select id,@rownum := @rownum +1 as i from ceshi order by ...

  8. ASP.NET Core 1.0: Using Entity Framework Core 1.0 - Transaction

    跟Entity Framework之前的版本不同,Class DbContext不再有AcceptAllChanges()方法. 使用Transaction需要使用DbContext中的Databas ...

  9. [UWP]通过自定义XamlCompositionBrushBase实现图片平铺

    1. 什么是XamlCompositionBrushBase 我早就想试试自定义XamlCompositionBrushBase,但一直没机会.上一篇文章介绍到使用Win2D的BorderEffect ...

  10. UML分析AsyncDisplayKit框架-ASMuplexImageNode异步下载时序图。

    PS:博客园图片服务器不正常工作,数据上传后服务器返回http500,园方迟迟还没解决. 我从2016-01-18 05:52向园方反馈问题-请问博客园的图片服务器有在正常运行吗,至此时2016-01 ...