PAT(甲级)2017年秋季考试

D题红黑树待补21/30

大佬的代码,看着想哭,这才是艺术啊

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;
cin>>x;
int len = getLen(x);
ll temp = x;
int t = 0;
ll right = 0;
ll rightTemp = 0;
ll left = 0;
while(t<len/2){
rightTemp = rightTemp * 10 + temp%10;
temp/=10;
t++;
}
while(rightTemp){
right = right * 10 + rightTemp%10;
rightTemp/=10;
}
left = temp;
if(left == 0 || right == 0){
puts("No");
}else{
if(x%(left*right) == 0) puts("Yes");
else puts("No");
}
}
return 0;
}

B Splitting A Linked List

链表题

#include<bits/stdc++.h>
using namespace std; const int maxn = 1010;
const int maxm = 100000;
struct node{
int address;
int data;
int next;
}nod[maxm]; vector<node> vec;
vector<node> ans;
int Head,n,k;
int vis[maxm]; int main(){
cin>>Head>>n>>k;
for(int i=1;i<=n;i++){
int add,dat,nex;
cin>>add>>dat>>nex;
nod[add].address = add;
nod[add].data = dat;
nod[add].next = nex;
}
for(int head = Head;head!=-1;head=nod[head].next){
vec.push_back(nod[head]);
}
for(int i=0;i<vec.size();i++){
if(vec[i].data < 0 && !vis[vec[i].address]){
ans.push_back(vec[i]);
vis[vec[i].address] = 1;
}
}
for(int i=0;i<vec.size();i++){
if(vec[i].data >= 0 && vec[i].data <= k && !vis[vec[i].address]){
ans.push_back(vec[i]);
vis[vec[i].address] = 1;
}
}
for(int i=0;i<vec.size();i++){
if(!vis[vec[i].address]){
ans.push_back(vec[i]);
vis[vec[i].address] = 1;
}
}
if(ans.size() == 1){
printf("%05d %d -1",ans[0].address,ans[0].data);
return 0;
}
for(int i=0;i<ans.size()-1;i++){
printf("%05d %d %05d\n",ans[i].address,ans[i].data,ans[i+1].address);
}
if(ans.size() > 1) printf("%05d %d -1",ans[ans.size()-1].address,ans[ans.size()-1].data);
return 0;
}

C Vertex Cover

简单图论,最小覆盖,邻接表存图

#include<bits/stdc++.h>
using namespace std; const int maxn = 10000;
int n,m,k;
int g[maxn][maxn];
int vis[maxn][maxn];
vector<int> vec;
void init(){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
vis[i][j] = 0;
}
}
} int main(){
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
g[u][v] = 1;
g[v][u] = 1;
}
cin>>k;
for(int t=0;t<k;t++){
init();
int nv;
cin>>nv;
for(int i=0;i<nv;i++) {
int d;
cin>>d;
vec.push_back(d);
}
for(int i=0;i<=nv-1;i++){
for(int j=0;j<n;j++){
if(g[vec[i]][j] == 1){
vis[vec[i]][j] = 1;
vis[j][vec[i]] = 1;
}
}
}
bool flag = true;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(g[i][j] == 1 && (vis[i][j] == 0 || vis[j][i] == 0)){
flag = false;
break;
}
}
if(flag == false) break;
}
if(flag) puts("Yes");
else puts("No");
vec.clear();
}
return 0;
}

D Is It A Red-Black Tree

判断是否红黑树 21分/30分 待补

#include<bits/stdc++.h>
using namespace std; /*
21分
*/ const int maxn = 1010;
int k,n;
int pre[maxn];
int rb[maxn];
int xb[maxn];
//bool childFlag = true;
struct node{
int v;
int cnt;
node *l;
node *r;
}; void insert(node *root,int pos){
if(root == NULL) return;
if(rb[pos] == 0){
root->cnt++;
}
if(root->v > pre[pos]){
if(root->l == NULL){
root->l = new node();
root->l->v = pre[pos];
root->l->l = NULL;
root->l->r = NULL;
if(rb[pos] == 0) root->l->cnt = 1;
}else{
insert(root->l,pos);
}
}else{
if(root->r == NULL){
root->r = new node();
root->r->v = pre[pos];
root->r->l = NULL;
root->r->r = NULL;
if(rb[pos] == 0) root->r->cnt = 1;
}else{
insert(root->r,pos);
}
}
} bool checkChild(node *Root){
if(Root->l){
if(rb[Root->v] < 0 && rb[Root->l->v] <0){
return false;
}else{
return checkChild(Root->l);
}
}
if(Root->r){
if(rb[Root->v] < 0 && rb[Root->r->v] <0){
return false;
}else{
return checkChild(Root->r);
}
}
return true;
} void init(){
for(int i=0;i<=n;i++){
rb[i] = 0;
xb[i] = 0;
pre[i] = 0;
}
} void bfs(node *root){
if(root == NULL) return;
cout<<root->v<<" "<<root->cnt<<endl;
if(root->l) bfs(root->l);
if(root->r) bfs(root->r);
} bool can = true;
void travel(node *root){
if(can == false) return;
if(root->v == 15){
int ddd = 1;
}
if(root->l && root->r){
if(root->l->cnt != root->r->cnt) {
can = false;
return;
}
}
if(root->l) {
travel(root->l);
}
if(root->r) {
travel(root->r);
}
} int main(){
cin>>k;
while(k--){
cin>>n;
init();
for(int i=1;i<=n;i++) {
int d;
cin>>d;
if(d < 0 ){
xb[-d] = 1;
rb[i] = 1;
pre[i] = -d;
}else{
rb[i] = 0;
pre[i] = d;
}
}
node *Root = new node();
Root->l = NULL;
Root->r = NULL;
Root->v = pre[1];
Root->cnt = 1;
for(int i=2;i<=n;i++) insert(Root,i);
if(rb[1] == 1) puts("No");
else if(checkChild(Root) == false) puts("No");
else{
//bfs(Root);
can = true;
travel(Root);
if(can == false) puts("No");
else puts("Yes");
}
}
return 0;
}

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

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

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

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

    PAT(甲级)2017年春季考试 A.Raffle for Weibo Followers #include<bits/stdc++.h> using namespace std; int ...

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

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

  4. 2019秋季PAT甲级_C++题解

    2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...

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

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

  6. pat甲级考试+pat1051+1056

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

  7. PAT甲级满分有感

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

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

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

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

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

随机推荐

  1. 使用“反向传播”迭代法求解y=√10

    X=√10,求X,也就是求Y=10 =X2 , X是多少. *重要的思想是,如何转化为可迭代求解的算法问题. *解数学问题,第一时间画图,求导,“直线化”. Y = X2 假如已知Y = 10 ,要求 ...

  2. 入门react

    前言:今天翻到了好久之前学习react时的笔记,拿出来记录一下以免忘掉,里面主要是记录了安装环境,创建项目,启动项目,jsx,组件介绍,组件通信,多层嵌套,路由搭建,路由传参,redux.记录的比较浅 ...

  3. 手写jwt验证,实现java和node无缝切换

    前言 前端时间和我朋友写了一个简易用户管理后台,功能其实很简单,涉及到的技术栈有:vue+elementUI,java+spring MVC以及node+egg,数据库用的mysql,简单方便. 一开 ...

  4. 【Elasticsearch 7 探索之路】(二)文档的 CRUD 和批量操作

    上一篇,我们介绍了什么是 Elasticsearch,它能做什么用以及基本概念(索引 Index.文档 Document.类型 Type)理解.这篇主要对 文档的基本 CRUD 和 倒排索引进行讲解. ...

  5. linux4.1内核配置以及编译及千兆网卡dp83867网卡驱动移植

    一  内核配置编译 1首先解压内核 tar jxvf linux-at91-4.1.tar.bz2: 2下载编译链 在ubuntu命令行中输入sudo apt-get install gcc-arm- ...

  6. jquery 数字滚动方法

    jquery 数字滚动方法用的是countUp.js这个插件 target = 目标元素的 ID:startVal = 开始值:endVal = 结束值:decimals = 小数位数,默认值是0:d ...

  7. map的线程安全问题

    为什么HashMap是线程不安全的 总说 HashMap 是线程不安全的,不安全的,不安全的,那么到底为什么它是线程不安全的呢?要回答这个问题就要先来简单了解一下 HashMap 源码中的使用的存储结 ...

  8. T-SQL Part XI: Login Failed 18456 以及修改Authentication Mode

    这是一个很常见的场景,安装SQL Server时候选择了默认的Windows Authentication Only,然后使用中发现还是需要支持用户名/密码登录. 按照MSDN的文档,然而并没有多大作 ...

  9. 列转行pivot函数在SQL Sever里面和Oracle里面的用法区别

    首先pivot是一个列转行的函数,反向用是unpivot(行转列). 在SQL sever中可以这么写 SELECT * FROM [TABLE] /*数据源*/ AS A PIVOT ( MAX/* ...

  10. TestNg练习001

    15分钟入门TestNG 阅读目录 TestNG介绍 在Eclipse中在线安装TestNG 在Eclipse中离线安装TestNg TestNG最简单的测试 TestNG的基本注解 TestNG中如 ...