7-1 Sexy Primes 判断素数 一个点没过17/20分

错因:输出i-6写成了输出i,当时写的很乱,可以参考其他人的写法

#include<bits/stdc++.h>
using namespace std; const int maxn = 1e8;
typedef long long ll;
int n; bool isprime(ll x){
if(x == 0 || x==1 || x==2) return false;
for(ll i=2;i<=sqrt(x);i++){
if(x%i==0) return false;
}
return true;
} int main(){
scanf("%lld",&n);
if(isprime(n)){
if(n>=6 && isprime(n-6)){
puts("Yes");
printf("%lld",n-6);
}else if(isprime(n+6)){
puts("Yes");
printf("%lld",n+6);
}else{
puts("No");
for(ll i=n+1;i<=maxn;i++){
if(i-6>=0){
if((i-6)>=0 && isprime(i) && isprime(i-6)){
printf("%lld",i);
break;
}
}else{
if(isprime(i) && isprime(i+6)){
printf("%lld",i);
break;
}
}
}
}
}else{
puts("No");
for(ll i=n+1;i<=maxn;i++){
if(i-6>=0){
if((i-6)>=0 && isprime(i) && isprime(i-6)){
printf("%lld",i);
break;
}
}else{
if(isprime(i) && isprime(i+6)){
printf("%lld",i);
break;
}
}
}
}
return 0;
}

修改后的代码:

#include<bits/stdc++.h>
using namespace std; const int maxn = 1e8+10;
typedef long long ll;
int n; bool isprime(ll x){
if(x == 0 || x==1 || x==2) return false;
for(ll i=2;i<=sqrt(x);i++){
if(x%i==0) return false;
}
return true;
} int main(){
scanf("%lld",&n);
printf("i = %d\n",ac);
if(isprime(n)){
if(n>=6 && isprime(n-6)){
puts("Yes");
printf("%lld",n-6);
}else if(isprime(n+6)){
puts("Yes");
printf("%lld",n+6);
}else{
puts("No");
for(ll i=n+1;i<=maxn;i++){
if(i-6>=0){
if((i-6)>=0 && isprime(i) && isprime(i-6)){
printf("%lld",i);
break;
}
}else{
if(isprime(i) && isprime(i+6)){
printf("%lld",i);
break;
}
}
}
}
}else{
puts("No");
for(ll i=n+1;i<=maxn;i++){
if(i-6>=0){
if((i-6)>=0 && isprime(i) && isprime(i-6)){
printf("%lld",i - 6);
break;
}else if(isprime(i) && isprime(i+6)){
printf("%lld",i);
break;
}
}else{
if(isprime(i) && isprime(i+6)){
printf("%lld",i);
break;
}
}
}
}
return 0;
}

7-2 Anniversary 集合、查找排序 25分

#include<bits/stdc++.h>
using namespace std; set<string> se1;
set<string> se2;
int n,m; int main(){
cin>>n;
for(int i=1;i<=n;i++){
string id;
cin>>id;
se1.insert(id);
}
int ans = 0;
string guestold = "99999999";
string assold = "99999999";
string guest;
string ass;
cin>>m;
for(int i=1;i<=m;i++){
string id;
cin>>id;
se2.insert(id);
string temp;
for(int j=6;j<=13;j++) temp.push_back(id[j]);
if(se1.find(id) != se1.end()){
ans++;
if(assold > temp) {
assold = temp;
ass = id;
}
}
if(guestold > temp) {
guestold = temp;
guest = id;
}
}
cout<<ans<<endl;
if(ans != 0){
if(n !=0){
cout<<ass<<endl;
}
}else{
if(m!=0){
cout<<guest<<endl;
}
}
return 0;
}

7-3 Telefraud Detection 图论 15/25分

更新错误原因:没有完全搞清题意,total duration,表示两人之间累计的通话时间

下面的代码只算了最后1次时间(覆盖)

修改后,可以用并查集做,不过感觉没必要,统计入度出度+暴力判断集合也不会超时的

参考链接





#include<bits/stdc++.h>
using namespace std; /*
邻接矩阵
点:出度 和他的边相关的入度
*/ const int maxn = 1010;
int k,n,m;
int g[maxn][maxn];
vector<int> sss;
int vis[maxn];
vector<int> temp;
set<int> se; void print(){
if(temp.size()==0) return;
cout<<temp[0];
for(int i=1;i<temp.size();i++){
cout<<" "<<temp[i];
}
cout<<endl;
} int main(){
cin>>k>>n>>m;
for(int i=1;i<=m;i++){
int u,v,w;
cin>>u>>v>>w;
g[u][v] = w;
}
for(int i=1;i<=n;i++){
int call = 0;
int back = 0;
for(int j=1;j<=n;j++){
if(g[i][j]!=0 && g[i][j] <= 5){
call++;
if(g[j][i] != 0) back++;
}
}
if(call > k && back*5 <= call){
sss.push_back(i);
se.insert(i);
}
}
if(sss.size() == 0){
cout<<"None"<<endl;
return 0;
}
sort(sss.begin(),sss.end());
for(int i=0;i<sss.size();i++){
int x = sss[i];
temp.clear();
if(!vis[x]){
vis[x] = 1;
temp.push_back(x);
for(int j=i+1;j<sss.size();j++){
//判断第sss[i]能否可以用
bool can = true;
for(int k=0;k<temp.size();k++){
if(g[sss[j]][temp[k]] == 0){
can = false;
break;
}
}
if(can == true){
vis[sss[j]] = 1;
temp.push_back(sss[j]);
}
}
print();
}
}
return 0;
}

7-4 Structure of a Binary Tree 二叉树中序后序建树,dfs深搜30分

#include<bits/stdc++.h>
using namespace std; int n,m;
const int maxn = 1100;
int in[maxn];
int post[maxn]; struct node{
int v;
node* l;
node* r;
};
int level[maxn];
int l[maxn];
int r[maxn];
int sib[maxn];
int par[maxn];
bool full = true; void dfs(node *root,int depth){
if(root == NULL) return;
int x = root->v;
level[x] = depth;
if(root->l != NULL){
par[root->l->v] = x;
l[x] = root->l->v;
dfs(root->l,depth+1);
}
if(root->r != NULL){
par[root->r->v] = x;
r[x] = root->r->v;
dfs(root->r,depth+1);
}
if(root->l != NULL && root->r != NULL){
sib[root->l->v] = root->r->v;
sib[root->r->v] = root->l->v;
}
if((root->l == NULL && root->r !=NULL) || (root->r == NULL && root->l !=NULL) ){
full = false;
}
} node* build(int il,int ir,int pl,int pr){
if(il > ir) return NULL;
int rootv = post[pr];
int pos = il;
while(pos <= ir && in[pos] != rootv) pos++;
node *root = new node;
root->v = rootv;
root->l = build(il,pos-1,pl,pr-(ir-pos)-1);
// pr-(ir-pos)+1
// root->r = build(pos+1,ir,pl+(pos-il)+1,pr);
root->r = build(pos+1,ir,pr-(ir-pos)+1,pr-1);
return root;
} int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>post[i];
for(int j=1;j<=n;j++) cin>>in[j];
node* Root = build(1,n,1,n);
dfs(Root,1);
cin>>m;
getchar();
while(m--){
string stat;
getline(cin, stat);
if(stat.find("root") != string::npos){
int root = 0;
for(int i=0;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') break;
root = root*10 + (stat[i] - '0');
}
if(root == Root->v){
puts("Yes");
}else{
puts("No");
}
}else if(stat.find("siblings") != string::npos){
int parent = 0;
int pos = 0;
for(int i=0;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') break;
parent = parent*10 + (stat[i] - '0');
pos = i;
}
int child = 0;
for(int i = pos+1;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') continue;
child = child*10 + (stat[i] - '0');
}
if(sib[parent] == child && sib[child] == parent){
puts("Yes");
}else{
puts("No");
}
}else if(stat.find("parent") != string::npos){
int parent = 0;
int pos = 0;
for(int i=0;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') break;
parent = parent*10 + (stat[i] - '0');
pos = i;
}
int child = 0;
for(int i = pos+1;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') continue;
child = child*10 + (stat[i] - '0');
}
if(par[child] == parent){
puts("Yes");
}else{
puts("No");
}
}else if(stat.find("left") != string::npos){
int parent = 0;
int pos = 0;
for(int i=0;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') break;
parent = parent*10 + (stat[i] - '0');
pos = i;
}
int child = 0;
for(int i = pos+1;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') continue;
child = child*10 + (stat[i] - '0');
}
if(l[child] == parent){
puts("Yes");
}else{
puts("No");
}
}else if(stat.find("right") != string::npos){
int parent = 0;
int pos = 0;
for(int i=0;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') break;
parent = parent*10 + (stat[i] - '0');
pos = i;
}
int child = 0;
for(int i = pos+1;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') continue;
child = child*10 + (stat[i] - '0');
}
if(r[child] == parent){
puts("Yes");
}else{
puts("No");
}
}else if(stat.find("same") != string::npos){
int parent = 0;
int pos = 0;
for(int i=0;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') break;
parent = parent*10 + (stat[i] - '0');
pos = i;
}
int child = 0;
for(int i = pos+1;i<stat.length();i++){
if(stat[i] > '9' || stat[i] < '0') continue;
child = child*10 + (stat[i] - '0');
}
if(level[parent] == level[child]){
puts("Yes");
}else{
puts("No");
}
}else if(stat.find("full") != string::npos){
if(full) puts("Yes");
else puts("No");
} }
return 0;
}

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

  1. PAT甲级2019冬季考试题解

    A Good In C纯模拟题,用string数组读入数据,注意单词数量的判断 #include<bits/stdc++.h> using namespace std; ; ][]; in ...

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

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

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

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

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

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

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

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

  6. PAT甲级考前整理(2019年3月备考)之一

       转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...

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

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

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

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

  9. pat甲级考试+pat1051+1056

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

随机推荐

  1. 羞,Java 字符串拼接竟然有这么多姿势

    二哥,我今年大二,看你分享的<阿里巴巴 Java 开发手册>上有一段内容说:"循环体内,拼接字符串最好使用 StringBuilder 的 append 方法,而不是 + 号操作 ...

  2. tslib1.1移植

    安装步骤: 1.准备工作确保以下软件已安装 # apt-get install autoconf(或autoconf2.13)# apt-get install automake# apt-get i ...

  3. day4-字符串专区

    1.字符串 str (用''or“”表示) 字符串中每个组成部分为字符,python中只要是用引号引起来的都叫字符串 ---特征: 加法 n1 = "alex" n2 = &quo ...

  4. Springboot中的缓存Cache和CacheManager原理介绍

    背景理解 什么是缓存,为什么要用缓存 程序运行中,在内存保持一定时间不变的数据就是缓存.简单到写一个Map,里面放着一些key,value数据,就已经是个缓存了 所以缓存并不是什么高大上的技术,只是个 ...

  5. 使用Rider中搭建specflow+xunit+selenium对web页面进行自动化功能测试环境

    运行rider,创建测试解决方案,选择xunit,点击create创建 ​   导入包,由于本人使用chrome浏览器(需先下载好对应的浏览器驱动),所以导入了selenium.webdriver.c ...

  6. ASP.NET Core 1.0: Deploy to IIS

    尽管ASP.NET最新的官方文档记录了如何Deploy to IIS,但是实际操作起来依旧磕磕绊绊.官方文档地址:https://docs.asp.net/en/latest/publishing/i ...

  7. [多态] java笔记之多态性

    1.多态,说的是对象,说的不是类. 2. 3.多态 = polymorphism 4. 调用如下: 5. 6.口诀: 7.对象的向上转型: 8.对象的向下转型: 9.下面这个异常叫做ClassCast ...

  8. API网关在API安全性中的作用

    从单一应用程序切换到微服务时,客户端的行为不能与客户端具有该应用程序的一个入口点的行为相同.简单来说就是微服务上的某一部分功能与单独实现该应用程序时存在不同. 目前在使用微服务时,客户端必须处理微服务 ...

  9. 类加载器 - ClassLoader详解

    获得ClassLoader的途径 获得当前类的ClassLoader clazz.getClassLoader() 获得当前线程上下文的ClassLoader Thread.currentThread ...

  10. 0MQ文档导读

    1. 先结合RabbitMQ Tutorials,弄清0MQ socket的各种类型. 1.1. 0MQ PAIR 对应 RabbitMQ Tutorials的 "Hello world&q ...