1152 Google Recruitment

思路:判断素数

#include<bits/stdc++.h>
using namespace std; const int maxn = 1100;
int a[maxn];
int n,k; long long getNum(int pos){
long long x = 0;
for(int i=pos;i<=pos+k-1;i++){
x = x*10 + a[i];
}
return x;
} bool prime(long long x){
if(x < 2) return false;
if(x == 2) return true;
int endss = sqrt(x);
for(int i=2;i<=endss;i++){
if(x%i == 0) return false;
}
return true;
} void print(long long x){
int len = 0;
long long temp = x;
while(temp){
temp/=10;
len++;
}
if(len == k) {
printf("%lld",x);
return;
}
int t = k - len;
while(t--)printf("0");
printf("%lld",x);
} int main(){
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%1d",&a[i]);
bool flag = false;
for(int i=1;i+k-1<=n;i++){
long long x = getNum(i);
if(prime(x)){
flag = true;
print(x);
break;
}
}
if(flag == false) puts("404");
return 0;
}

1153 Decode Registration Card of PAT

思路:结构体排序,map计数,string.c_str()把字符串转成字符数组后可以使用print输出

注意:使用太多cin、cout太慢了会超时

#include<bits/stdc++.h>
//#include<unordered_map>
using namespace std; /*
Cin和Cout不能用太多啦
除了string 和 char类型的输入 最好把Cin替换成scanf
Cout全部换成printf 对于string类型的printf 需要将string转换成字符数组
string.c_str();
*/ const int maxn = 1e4+10;
int n,m;
struct node{
char type;
int site;
string date;
int num;
int score;
string all;
};
struct node stu[maxn];
vector<node> ans; bool cmp1(node s1,node s2){
if(s1.score == s2.score) {
s1.all < s2.all;
}
return s1.score > s2.score;
} bool cmp2(node s1,node s2){
if(s1.score > s2.score) return true;
else if(s1.score < s2.score) return false;
return s1.all < s2.all;
}
int mm[1001];
struct nod{
int site;
int num;
nod(int sss,int nnn){
site = sss;
num = nnn;
}
};
vector<nod> ans3;
bool cmp3(nod s1,nod s2){
if(s1.num == s2.num) return s1.site < s2.site;
return s1.num > s2.num;
}
int main(){
// cin>>n>>m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
string str;
int score;
// cin>>str>>score;
cin>>str;
// scanf("%s",&str);
scanf("%d",&score);
stu[i].all = str;
stu[i].score = score;
stu[i].type = str[0];
stu[i].site = (str[1] - '0') * 100 + (str[2] - '0') * 10 + (str[3] - '0');
stu[i].date = str.substr(4,6);
stu[i].num = (str[10] - '0') * 100 + (str[11] - '0') * 10 + (str[12] - '0');
}
for(int Case=1;Case<=m;Case++){
int Type;
// cin>>Type;
scanf("%d",&Type);
int cnt = 0;
ans.clear();
ans3.clear();
if(Type == 1){
char type;
cin>>type;
printf("Case %d: 1 %c\n",Case,type);
for(int i=1;i<=n;i++){
if(stu[i].type == type){
ans.push_back(stu[i]);
}
}
cnt = ans.size();
if(cnt == 0){
puts("NA");
}else{
sort(ans.begin(),ans.end(),cmp2);
for(int i=0;i<=cnt-1;i++){
// cout<<ans[i].all<<" "<<ans[i].score<<endl;
printf("%s ",ans[i].all.c_str());
printf("%d\n",ans[i].score);
}
}
}else if(Type == 2){
int site;
// cin>>site;
scanf("%d",&site);
printf("Case %d: 2 %d\n",Case,site);
int tot = 0;
for(int i=1;i<=n;i++){
if(stu[i].site == site){
tot += stu[i].score;
cnt++;
}
}
if(cnt == 0){
puts("NA");
}else{
printf("%d %d\n",cnt,tot);
}
}else if(Type == 3){
string date;
cin>>date;
printf("Case %d: 3 ",Case);
// cout<<date<<endl;
printf("%s\n",date.c_str());
for(int i=100;i<=999;i++) mm[i] = 0;
for(int i=1;i<=n;i++){
if(stu[i].date == date){
mm[stu[i].site]++;
}
}
for(int i=100;i<=999;i++){
if(mm[i] != 0){
ans3.push_back(nod(i,mm[i]));
}
}
// map<int, int> mp;
// for(int i=1;i<=n;i++){
// if(stu[i].date == date) mp[stu[i].site]++;
// }
// map<int, int>::iterator it = mp.begin();
// while(it!=mp.end()){
// ans3.push_back(nod(it->first,it->second));
// it++;
// cnt++;
// }
cnt = ans3.size();
if(cnt == 0){
puts("NA");
}else{
sort(ans3.begin(),ans3.end(),cmp3);
for(int i=0;i<=cnt-1;i++){
// cout<<ans3[i].site<<" "<<ans3[i].num<<endl;
printf("%d %d\n",ans3[i].site,ans3[i].num);
}
}
}
}
return 0;
}

1154 Vertex Coloring

思路:图论,dfs遍历检查相邻结点的颜色

#include<bits/stdc++.h>
using namespace std; const int maxn = 10010;
int n,m,k;
vector<int> g[maxn];
int col[maxn];
int vis[maxn];
set<int> se;
bool flag = false; void dfs(int x){
if(flag == false) return;
vis[x] = 1;
for(int i=0;i<g[x].size();i++){
int v = g[x][i];
if(col[x] == col[v]) flag = false;
if(!vis[v]) dfs(v);
}
} 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);
}
cin>>k;
while(k--){
se.clear();
for(int i=0;i<n;i++){
cin>>col[i];
se.insert(col[i]);
vis[i] = 0;
}
flag = true;
for(int i=0;i<n;i++){
if(flag == false) break;
if(vis[i]) continue;
dfs(i);
}
if(flag) cout<<se.size()<<"-coloring"<<endl;
else cout<<"No"<<endl;
}
return 0;
}

1155 Heap Paths

思路:给定序列,判断是否大根堆、小根堆(特殊二叉树)

#include<bits/stdc++.h>
using namespace std; const int maxn = 50010;
int n;
int g[maxn];
vector<int> v;
bool flagMin = false;
bool flagMax = false;
bool flag = true; void dfs(int x){
v.push_back(g[x]);
if(x * 2 + 1 <= n){
dfs(x * 2 + 1);
}
if(x * 2 <= n){
dfs(x * 2);
}
if(x * 2 + 1 > n && x * 2 > n){
int temp = v[0];
if(flag){
int cnt = 0;
for(int i=0;i<v.size();i++){
if(i > 0 && v[i] >= v[i-1]) cnt++;
}
if(cnt == v.size() - 1) flagMax = true;
else if(cnt == 0) flagMin = true;
else flag = false;
}
for(int i=0;i<v.size();i++){
if(i == 0) cout<<v[i];
else cout<<" "<<v[i];
}
if(v.size() != 0) cout<<endl;
}
v.erase(v.end()-1);
} int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>g[i];
dfs(1);
if(flag == false){
cout<<"Not Heap"<<endl;
}else if(flagMin == true && flagMax == false){
cout<<"Max Heap"<<endl;
}else if(flagMin == false && flagMax == true){
cout<<"Min Heap"<<endl;
}else{
cout<<"Not Heap"<<endl;
}
return 0;
}

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

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

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

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

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

  3. pat甲级考试+pat1051+1056

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

  4. PAT甲级满分有感

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

  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甲级_备考总结

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

  8. PAT甲级题分类汇编——计算

    本文为PAT甲级分类汇编系列文章. 计算类,指以数学运算为主或为背景的题. 题号 标题 分数 大意 1058 A+B in Hogwarts 20 特殊进制加法 1059 Prime Factors ...

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

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

随机推荐

  1. mysql分组和去重同时使用

    这是我的数据结构: 这是我的统计SQL

  2. [开源]基于goapp+xterm实现webssh-网页上的SSH终端(golang)

    简析 基于goapp+xterm实现webssh-网页上的SSH终端. 开源地址见文末. 特性 在网页上实现一个SSH终端.从而无需Xshell之类的模拟终端工具进行SSH连接. 可以对交互命令进行审 ...

  3. CSPS Oct目标

    超过skyh 删了一些sb话,不过目标不会变的

  4. introduce new products

    Today's the day. I'm giving you the heads up. Our company is rolling up its new line of cell phones. ...

  5. vue之注册自定义的全局js方法

    前端开发的时候,总会需要写一些js方法,在vue框架中为了方便使用,可以考虑注册一个全局的js方法,下面是注册步骤: 1.0 可以在assets文件中的js文件下面新建一个js文件,如:yun.js- ...

  6. 小白历险记:spingboot之helloworld

    还记得入职第一天的时候,先安装了相关的软件,配置了环境.boss叫我写的第一个程序:搭建一个springboot工程,输出helloworld. 哈哈话不多说,回忆一下. 1.打开IDEA,点击Cre ...

  7. Pandas进阶笔记 (一) Groupby 重难点总结

    如果Pandas只是能把一些数据变成 dataframe 这样优美的格式,那么Pandas绝不会成为叱咤风云的数据分析中心组件.因为在数据分析过程中,描述数据是通过一些列的统计指标实现的,分析结果也需 ...

  8. Go组件学习——Web框架Gin

    以前学Java的时候,和Spring全家桶打好关系就行了,从Spring.Spring MVC到SpringBoot,一脉相承. 对于一个Web项目,使用Spring MVC,就可以基于MVC的思想开 ...

  9. Error response from daemon ... no space left on device docker启动容器服务报错

    docker 启动容器服务的时候,报错no space left on device 1. 检查磁盘是否用光 3.检查inode是否耗光,从截图看到是inode耗光导致出现问题: 进入到/run里面看 ...

  10. 创建基于OData的Web API - Knowledge Builder API, Part IV: Write Controller

    基于上一篇<创建基于OData的Web API - Knowledge Builder API, Part III:Write Model and Controller>,新创建的ODat ...