算是第二次做这套题吧,感觉从上次考试到现在自己有了挺大提高,提前30min做完了。

7-1 Sexy Primes

  读懂题意就行。

 #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector> using namespace std;
bool isPrime(int n)
{
if(n < )
return false;
int tmpNum = (int)sqrt(1.0*n);
for(int i = ; i <= tmpNum; ++ i)
{
if(n % i == )
return false;
}
return true;
}
int main()
{
int tmpNum, prime1 = -;
cin >> tmpNum;
if(isPrime(tmpNum))
{
if(tmpNum > && isPrime(tmpNum-))
prime1 = tmpNum-;
else if(isPrime(tmpNum+))
prime1 = tmpNum + ;
}
prime1 == - ? cout << "No" << endl : cout << "Yes" << endl;
for(int i = tmpNum-; prime1 == -;i ++)
{
if(isPrime(i) && isPrime(i+))
{
if(i > tmpNum)
prime1 = i;
else
prime1 = i +;
} }
cout << prime1;
return ;
}

7-2 Anniversary

  也是读懂题意就行。

 #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <string>
#include <cstdlib>
using namespace std;
unordered_map<string, int> alumFlagMap;
int main()
{
int n, tmpNum, oldGuestNum = , oldAlumNum = ;
string tmpStr, oldGuest, oldAlum;
cin >> n;
while(n--)
{
cin >> tmpStr;
alumFlagMap[tmpStr] = ;
}
cin >> n;
int cnt = ;
while(n--)
{
cin >> tmpStr;
if(alumFlagMap[tmpStr] > )
{
tmpNum = atoi(tmpStr.substr(,).c_str());
if(tmpNum < oldAlumNum)
{
oldAlumNum = tmpNum;
oldAlum = tmpStr;
}
cnt ++;
}
else
{
tmpNum = atoi(tmpStr.substr(,).c_str());
if(tmpNum < oldGuestNum)
{
oldGuestNum = tmpNum;
oldGuest = tmpStr;
}
}
}
cout << cnt << endl;
cnt == ? cout << oldGuest << endl : cout << oldAlum << endl; return ;
}

7-3 Telefraud Detection

  这道题目理清条件就行,先找到嫌疑人,在根据嫌疑人找团伙,团伙进行并查集处理

      1.嫌疑人:给大于K个人打短电话,且不超过20%的人回拨。

      2.团伙:两个嫌疑人互相打过电话。

   3.短电话:A拨打B电话的总时长不超过5分钟,认为A向B打短电话。

 #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <cstring>
using namespace std; #define MAX_AMOUNT 1010
const int INF = 0x7f7f7f7f;
#define CLR(a,b) memset(a,b,sizeof(a))
int callInfo[MAX_AMOUNT][MAX_AMOUNT];
int fatherId[MAX_AMOUNT+];
int K, N, M;
vector<int> susPeopleVec;
vector<int> phoneNumCnt[MAX_AMOUNT];
unordered_map<int, int> susPeopleMap;
int getFather(int u)
{
int tmpNum = u;
while(fatherId[tmpNum] != tmpNum)
tmpNum = fatherId[tmpNum];
int tmpFa = tmpNum;
tmpNum = u;
while(fatherId[tmpNum] != tmpNum)
{
u = tmpNum;
tmpNum = fatherId[tmpNum];
fatherId[u] = tmpFa;
}
return tmpFa;
}
int main()
{
int tmpNum, tmpSt, tmpEnd, tmpTime, susCnt = ;
cin >> K >> N >> M;
CLR(callInfo, );
while(M--)
{
cin >> tmpSt >> tmpEnd >> tmpTime;
callInfo[tmpSt][tmpEnd] += tmpTime;
}
for(int i = ; i <= N; ++ i)
{
int shortCallCnt = ;
int rebackCnt = ;
for(int j = ; j <= N; ++ j)
{
if(callInfo[i][j] > && callInfo[i][j] <= )
{
shortCallCnt ++;
if(callInfo[j][i] > )
rebackCnt ++;
}
}
if(shortCallCnt > K && 1.0*rebackCnt/shortCallCnt <= 0.2)
{
susPeopleMap[i] = ;susCnt++;susPeopleVec.push_back(i);
}
}
for(int i = ; i <= N; ++ i)
{
fatherId[i] = i;
}
int index;
for(int i = ; i < susPeopleVec.size(); ++ i)
{
index = susPeopleVec[i];
for(int j = ; j <= N; ++ j)
{
if(susPeopleMap[j] == )
continue;
if(callInfo[index][j] > && callInfo[j][index] > )
{
int tmpF1 = getFather(index);
int tmpF2 = getFather(j);
if(tmpF1 > tmpF2)
{
fatherId[tmpF1] = tmpF2;
getFather(index);
}
else
{
fatherId[tmpF2] = tmpF1;
getFather(j);
}
}
}
}
if(susPeopleVec.size() == )
{
cout << "None" << endl;
return ;
}
for(int i = ; i < susPeopleVec.size(); ++ i)
phoneNumCnt[fatherId[susPeopleVec[i]]].push_back(susPeopleVec[i]);
for(int i = ; i <= N; ++ i)
{
if(phoneNumCnt[i].size() > )
{
bool symbolFlag = false;
for(auto it = phoneNumCnt[i].begin(); it != phoneNumCnt[i].end(); ++ it)
{
symbolFlag ? printf(" ") : symbolFlag = true;
printf("%d", *it);
}
printf("\n");
}
}
return ;
}

7-4 Structure of a Binary Tree

  这种判断是否正确的题目,一般选择比较适合查找的顺序存储结构

  首先根据题目给出的后序和先序顺序,在数组中将该二叉树建立出来。

  之后便是提取题目给出的结论中的数字,这个自己写个函数就可以搞定。

  最后便是利用string.find()的查找功能确定结论是哪一种,然后进行判断(因为是顺序存储,判断会相当简单)。

  (代码有点啰嗦,赶时间哈)

 #include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <cstring>
using namespace std; #define MAX_AMOUNT 1010
const int INF = 0x7f7f7f7f;
#define CLR(a,b) memset(a,b,sizeof(a))
int N, M;
bool fullFlag = true;
vector<int> postVec, inorderVec;
vector<int> treeVec();
unordered_map<int, int> nodeIndexMap;
bool createTree(int inL, int inR, int postL, int postR, int nodeIndex)
{
if(inL > inR || postL > postR)
return false;
int tmpNum = postVec[postR];
int index = inL;
while(inorderVec[index] != tmpNum)
index++;
treeVec[nodeIndex] = tmpNum;
nodeIndexMap[tmpNum] = nodeIndex;
int childCnt = ;
if(createTree(inL, index-, postL, postL+index--inL, nodeIndex*))
childCnt ++;
if(createTree(index+, inR, postR-inR+index, postR-, nodeIndex*+))
childCnt ++;
if(childCnt == )
fullFlag = false;
return true;
}
int getNumber(string tmpStr)
{
bool flag = false;
int index = ;
while(index < tmpStr.size())
{
if(isdigit(tmpStr[index]))
break;
index ++;
}
int endIndex = index;
while(endIndex < tmpStr.size())
{
if(!isdigit(tmpStr[endIndex]))
{
break;
}
endIndex++;
}
return atoi(tmpStr.substr(index, endIndex-index).c_str());
}
int main()
{
cin >> N;
int tmpNum;
postVec.resize(N);
inorderVec.resize(N);
for(int i = ; i < N; ++ i)
cin >> postVec[i];
for(int i = ; i < N; ++ i)
cin >> inorderVec[i]; createTree(, N-, , N-, );
cin >> M;
getchar();
string tmpStr;
while(M--)
{
getline(cin, tmpStr);
if(tmpStr[tmpStr.size()-] == 't')
{
getNumber(tmpStr) == treeVec[] ? printf("Yes\n") : printf("No\n");
}
else if(tmpStr[] == 'I')
{
fullFlag ? printf("Yes\n") : printf("No\n");
}
else if(tmpStr[tmpStr.size()-] == 's')
{
int tmpNum1 = getNumber(tmpStr.substr(,));
int tmpNum2 = getNumber(tmpStr.substr(,));
tmpNum1 = nodeIndexMap[tmpNum1];
tmpNum2 = nodeIndexMap[tmpNum2];
if((tmpNum1%== && tmpNum2-tmpNum1==)||tmpNum1%== && tmpNum1-tmpNum2==)
{
printf("Yes\n");
}
else
printf("No\n");
}
else if(tmpStr[tmpStr.size()-] == 'l')
{
int tmpNum1 = getNumber(tmpStr.substr(,));
int tmpNum2 = getNumber(tmpStr.substr(,));
tmpNum1 = nodeIndexMap[tmpNum1];
tmpNum2 = nodeIndexMap[tmpNum2];
int cnt = ;
while(tmpNum1 > )
{
tmpNum1 /= ;
cnt++;
}
while(tmpNum2 > )
{
tmpNum2 /= ;
cnt --;
}
if(cnt == )
printf("Yes\n");
else
printf("No\n");
}
else
{
int tmpNum1 = getNumber(tmpStr.substr(,));
int tmpNum2 = getNumber(tmpStr.substr(tmpStr.size()-,));
tmpNum1 = nodeIndexMap[tmpNum1];
tmpNum2 = nodeIndexMap[tmpNum2];
if(tmpStr.find("left")!=tmpStr.npos)
{
tmpNum1 == tmpNum2* ? printf("Yes\n") :printf("No\n");
}
else if(tmpStr.find("right")!=tmpStr.npos)
{
tmpNum1 == tmpNum2*+ ? printf("Yes\n") :printf("No\n");
}
else
{
tmpNum1 == tmpNum2/ ? printf("Yes\n") :printf("No\n");
}
}
}
return ;
}

PAT 2019 春的更多相关文章

  1. 2019春《C语言程序设计》课程设计的安排

    课程设计的安排 课前准备: 要求同学们注册码云,并登陆: 要求组长加入由老师创建的一级组织:"2019春C语言": 要求组长建立二级组织,给自己的小组取个好听的名字,并邀请本组成员 ...

  2. 2019春第九周作业Compile Summarize

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 这里 我在这个课程的目标是 能更加进一步的够熟练掌握指针的用法 这个作业在那个具体方面帮助我实现目标 能解更多的题 参考文献与网址 C语言 ...

  3. 2019春招——Vivo大数据开发工程师面经

    Vvio总共就一轮技术面+一轮HR面,技术面总体而言,比较宽泛,比较看中基础,面试的全程没有涉及简历上的东西(都准备好跟他扯项目了,感觉是抽取的题库...)具体内容如下: 1.熟悉Hadoop哪些组件 ...

  4. PAT 2019 秋

    考试的还行.不过略微有点遗憾,但是没想到第一题会直接上排序和dfs,感觉这次的题目难度好像是倒着的一样.哈哈哈哈. 第一题实在是搞崩心态,这道题给我的感觉是,可以做,但事实上总是差点啥. 第二题,第三 ...

  5. PAT 2018 春

    A 1140 Look-and-say Sequence 简单模拟.可能要注意字符串第一个字符和最后一个字符的处理. #include <cstdio> #include <iost ...

  6. 京东2019春招Java工程师编程题题解

    生成回文串 题目描述 对于一个字符串,从前开始读和从后开始读是一样的,我们就称这个字符串是回文串. 例如"ABCBA","AA","A"是回 ...

  7. Python题集:2019春Python程序设计选修课习题笔记

    一.判断题: 1-1.在Python 3.x中可以使用中文作为变量名. 答案:√ 1-2.Python变量使用前必须先声明,并且一旦声明就不能再当前作用域内改变其类型. 答案:× 1-3.Python ...

  8. 2019春招面试高频题(Java版),持续更新(答案来自互联网)

    第一模块--并发与多线程 Java多线程方法: 实现Runnable接口, 继承thread类, 使用线程池 操作系统层面的进程与线程(对JAVA多线程和高并发有了解吗?) 计算机资源=存储资源+计算 ...

  9. 2019春第十周作业Compile Summarize

    这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 在这里 我在这个课程的目标是 能够对C语言的编写更加得心应手 这个作业在那个具体方面帮助我实现目标 结构体更进一步 参考文献与网址 C语言 ...

随机推荐

  1. ffmpeg 学习: 003-关键函数介绍

    背景 了解一些关键函数对于开发的帮助比较大. avformat_open_input FFMPEG 打开媒体的过程开始于 avformat_open_input,因此该函数的重要性不可忽视. 在该函数 ...

  2. D - Recommendations

    就是有n组,每组的数量是num,只能增加数字,增加的代价为t,求能使所有组的数量都不同的最小代价. #include<bits/stdc++.h> #define N 200005 #de ...

  3. pom.xml报unknown error

    1. 从https://start.spring.io/的spring initializr生成demo,使用默认的2.1.6.release(2019年7月10日) 2. 在eclipse加载后,p ...

  4. C语言备忘录——取余与取模

    前几天,一个小姐姐问我取余和取模有什么区别,我当时第一反应就是二者是一样的,但是小姐姐咬死说不一样.我去百度了一下还真的不一样.脑壳疼,我当初误导了多少人.所以为了帮助我记忆也为了帮助预防我误人子弟 ...

  5. uniapp 小程序实现自定义底部导航栏(tarbar)

    在小程序开发中,默认底部导航栏很难满足实际需求,好在官方给出了自定义形式,效果如下: 话不多说,直接上代码 1.组件 custom-tarbar.vue文件 <template> < ...

  6. ffmpeg “inttypes.h”: No such file or directory

    编译过程:错误一:无法打开包括文件:“inttypes.h”: No such file or directory解决方法:删除之,并在其之前添加如下代码: #if defined(WIN32) &a ...

  7. .Net 经典案例

    1.捕捉一只小可爱 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

  8. C++编程学习(十)引用

    引用变量是一个别名,也就是说,它是某个已存在变量的另一个名字.一旦把引用初始化为某个变量,就可以使用该引用名称或变量名称来指向变量. 注意以下几点与指针的区别: 不存在空引用.引用必须连接到一块合法的 ...

  9. Local-Pref(本地优先属性)路由本地优先术

    Local-Pref(本地优先属性)路由本地优先术: ①:抓取感兴趣流量——前缀与访问——prefix and access ②:创建路由地图——router-map ③:第一法则——permit 1 ...

  10. git 在企业里的基本操作

    拖下来码云上的代码: git add . 若把单个文件加入到暂存区,则用git add 某文件 若把所有文件加入到暂存区,则使用git add . git commit -m"提交" ...