PAT(甲级)2017年春季考试

PAT(甲级)2017年春季考试

C题图论欧拉回路,还没写,因为太饿了,待补

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

还没做,图论,欧拉回路

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;
}

原文地址:https://www.cnblogs.com/fisherss/p/11994468.html

时间: 2024-08-30 01:34:14

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

PAT(甲级)2017年秋季考试

PAT(甲级)2017年秋季考试 还有一题由于上午心情复杂..没调试完.待补. A Cut Integer 模拟题 #include<bits/stdc++.h> using namespace std; typedef long long ll; int n; int getLen(ll x){ int len = 0; while(x){ len++; x/=10; } return len; } int main(){ cin>>n; while(n--){ ll x; ci

PAT甲级考试题库1001 A+B Format 代码实现及相关知识学习

准备参加九年九月份的PAT甲级证书考试,对网站上的题目进行总结分析: 1001题 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). 计算a+b的值并以一定格式输出其和sum(数字需要

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

2017年精算师考试准考证打印入口及流程

2017年精算师考试将在10月28日至24日进行,距离精算师考试时间还是有28天.由于考试时间即将来临,在考试临近的时候,考生们最关心的问题就是精算师考试准考证打印的相关问题,今天小编就来告诉大家探讨一下. 相信还有大部分考生还不清楚精算师考试准考证打印入口在哪里,其实考生们只需要在网上直接进入中国精算师协会官网,就可以打印准考证了. 当然对于很多第一次报名参加精算师考试的考生来说,对于这一块没有什么经验,所以为大家梳理了一下精算师考试准考证打印的具体流程,以供大家参考. 1.请报名成功的考生在

【临时重发】复旦大学 在职软件工程硕士(双证)2017年入学考试 参考书推荐

[临时重发]复旦大学 在职软件工程硕士(双证)2017年入学考试 参考书推荐 2017-06-04 MSE热线 复旦MSE热线 (一)统考科目:(除了政治时政版(现在还没有),不一定要所谓2018版) 政治理论 (1)<全国硕士研究生招生考试 思想政治理论 考试大纲>,教育部考试中心,高等教育出版社,10元. (2)<全国硕士研究生招生考试 思想政治理论 考试大纲解析>,教育部考试中心,高等教育出版社,59元. 英语(二) (1)<全国硕士研究生招生考试 英语(二) 考试大纲

.NET Core 2.0版本预计于2017年春季发布

英文原文: NET Core 2.0 Planned for Spring 2017 微软项目经理 Immo Landwerth 公布了即将推出的 .NET Core 2.0 版本的细节,该版本预计于 2017 年春季发布.这是 .NET Core 平台的一个重要发布,因为 2.0 版本对 .NET Core 的各项功能都有显著扩展. 言归正传,我们来看看即将发布的.NET Core 1.0 版本.按计划它将在 Visual Studio 2017 的正式发布会上推出.但是该版本仍将遵循 .NE

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.

PAT甲级专题|最短路

PAT甲级最短路 主要算法:dijkstra 求最短最长路.dfs图论搜索. 1018,dijkstra记录路径 + dfs搜索路径最值 25分,错误点暂时找不出.. 如果只用dijkstra没法做,只能得20分 #include<bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 510; int cmax,n,ter,m; int caps[maxn]; int g[maxn][m

【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全部出手的利润.输出最大利润. trick: 测试点2可能包含M不为整数的数据.(尽管题面说明M是正整数,可是根据从前PAT甲级题目的经验,有可能不是整数.....) 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using names