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++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...
随机推荐
- 前端与算法 leetcode 350. 两个数组的交集 II
目录 # 前端与算法 leetcode 350. 两个数组的交集 II 题目描述 概要 提示 解析 解法一:哈希表 解法二:双指针 解法三:暴力法 算法 # 前端与算法 leetcode 350. 两 ...
- 在线热备份数据库之innobackupex 完整备份InnoDB
在线热备份数据库innobackupex 完整备份InnoDB XtraBackup xtrabackup C程序,支持InnoDB/XtraDB innobackupex : 以Perl脚本封装xt ...
- Linux | 性能分析系列学习 (2)
常分析方法: 1.监控大盘,是否异常报警 2..平均负载情况,(top / htop )平均负载体现的是系统的一个整体情况,他应该是cpu.内存.磁盘性能的一个综合,一般是平均负载的值大于 ...
- PHP获取PHP执行的时间
php获取PHP执行的时间 <pre> //程序运行时间 $starttime = explode(' ',microtime()); //代码区域 //程序运行时间 $endtime = ...
- python模块——socket
实例一. server: #socket套接字(IP + 端口号)(qq,wechat 发送接收消息依靠socket模块),cs架构import socketserver = socket.socke ...
- Linux命令实践( 六)
1.统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来 [root@test ~]#awk -F: '{shells[$NF]++;if($ ...
- MySql——创建数据表,查询数据,排序查询数据
参考资料:<Mysql必知必会> 创建数据表 在学习前首先创建数据表和插入数据.如何安装mysql可以看看上个博客https://www.cnblogs.com/lbhym/p/11675 ...
- SQL Server 2014:在修改表的内容时,提示“此单元格已更改,尚未将更改提交到数据库”,怎么处理?
那一行上的属性为“不允许为null”的所有字段都填上对应信息,按回车键或者点击下一行任意一个单元格便会自动将更改的信息提交到数据库.
- [ERROR]Unable to locate package
刚更换了DNS,需要更新下apt-get $ apt-get update
- 后台开发小白必学服务器框架——UDPServer
毕业后加入了一家大型的互联网公司的音视频产品部门做后台开发,其实我本身是学习自动化的,研究生的方向嵌入式系统,对互联网可是一知半解,因此能进入这样一个大公司还是很幸运的. 刚开始工作的半年应该是在上份 ...