pat乙级每日习题
欢迎加入我们:qq群:1054587486
1:https://pintia.cn/problem-sets/994805260223102976/problems/994805325918486528
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 int main(int argc, char const *argv[])
5 {
6 int n;cin >> n;
7 int ans = 0;
8 while(n != 1){
9 if((n & 1) == 1){
10 n = (n * 3 + 1) >> 1;
11 }else{
12 n >>= 1;
13 }
14 ++ans;
15 }
16 cout << ans << endl;
17 return 0;
18 }
2:https://pintia.cn/problem-sets/994805260223102976/problems/994805320306507776
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 const int N = 110;
5
6 int arr[N];
7 int n;
8
9 int main(int argc, char const *argv[])
10 {
11 unordered_map<int, bool> hash;
12
13 cin >> n;
14 for(int i = 1;i <= n;++i){
15 cin >> arr[i];//存进数组因为求答案要用
16 int x = arr[i];
17 //把x最终变成1的所有中间的数都置为true,代表出现过
18 while(x != 1){
19 if((x & 1) == 1) //&1 == 1 代表是奇数
20 x = (3 * x + 1) >> 1;
21 else
22 x >>= 1;
23 hash[x] = true;
24 }
25 }
26
27 vector<int> ans;
28 //把数组中的数没有被覆盖过的也就是 false 的加进答案
29 for(int i = 1;i <= n;++i)
30 if(!hash[arr[i]])
31 ans.push_back(arr[i]);
32 //以下代码完全是为了格式化输出
33 sort(ans.begin(), ans.end(), greater<int>());
34 for(int i = 0;i < ans.size()-1;++i)
35 cout << ans[i] << " ";
36 cout << ans[ans.size()-1];
37 cout << endl;
38
39 return 0;
40 }
3:https://pintia.cn/problem-sets/994805260223102976/problems/994805317546655744
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 const int N = 1e5;
5
6 int n;
7 bool state[N];
8
9 int main(int argc, char const *argv[])
10 {
11 cin >> n;
12 int ans = 0;
13 int pre = -1;
14 for(int i = 2;i <= n;++i){
15 if(!state[i]){
16 if(i - pre == 2)
17 ++ans;
18 pre = i;
19 for(int j = i + i; j <= n; j += i)
20 state[j] = true;
21 }
22 }
23 cout << ans << endl;
24 return 0;
25 }
4:https://pintia.cn/problem-sets/994805260223102976/problems/994805296180871168
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 const int N = 1e5+10;
5
6 struct Node{
7 int val;
8 int next;
9 }node[N];
10
11 int head;
12 int n, k;
13
14 int revers(int cur, int t){
15 int pre = -1;
16 while(cur != t){
17 int tmp = node[cur].next;
18 node[cur].next = pre;
19 pre = cur;
20 cur = tmp;
21 }
22 return pre;
23 }
24
25 int help(int h){
26 if(h == -1) return h;
27 int tail = h;
28 for(int i = 0;i < k;++i){
29 tail = node[tail].next;
30 if(tail == -1) return h;
31 }
32 int newh = revers(h, tail);
33 node[h].next = help(tail);
34 return newh;
35 }
36
37 int main(){
38 cin >> head >> n >> k;
39 for(int i = 1;i <= n;++i){
40 int x;cin >> x;
41 cin >> node[x].val >> node[x].next;
42 }
43 int newhead = help(head);
44 for(int i = newhead;i != -1;i = node[i].next)
45 if(node[i].next == -1)
46 printf("%05d %d %d\n", i, node[i].val, node[i].next);
47 else
48 printf("%05d %d %05d\n", i, node[i].val, node[i].next);
49 return 0;
50 }
持续更新中...
pat乙级每日习题的更多相关文章
- C#版 - PAT乙级(Basic Level)真题 之 1021.个位数统计 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - P ...
- PAT乙级真题及训练题 1025. 反转链表 (25)
PAT乙级真题及训练题 1025. 反转链表 (25) 感觉几个世纪没打代码了,真是坏习惯,调了两小时把反转链表调出来了,心情舒畅. 这道题的步骤 数据输入,数组纪录下一结点及储存值 创建链表并储存上 ...
- PAT 乙级 1024
题目 题目地址:PAT 乙级 1024 题解 模拟题,重点需要考虑到各种不同情况:简单来说一下: 因为输入格式固定,所以把不同的部分分别存储和处理可以在很大程度上简化运算:其中需要考虑最多的就是小数部 ...
- PAT 乙级 1017
题目 题目地址:PAT 乙级 1017 题解 粗看是一道大数除法题,实际上只不过是通过字符数组模拟除法过程,理解之后还是比较简单的: 具体分析一下本题: 因为题设中的除数(n)是一位整数,因此大幅简化 ...
- PAT 乙级 1015
题目 题目地址:PAT 乙级 1015 题解 常规题,难点在于理清楚排序规则,通过比较简洁的方式进行编码: 在这里我选择使用vector进行存储,并使用sort方法排序,因为本题不是简单按照大小排序, ...
- PAT 乙级 1003
题目 题目地址:PAT 乙级 1003 题解 规律观察题,本题的关键在于把题读懂,同时还有几个比较容易疏忽的地方需要注意:总之这道题要考虑的东西更多,细节上也要特别注意: 规律:“如果 aPbTc 是 ...
- PAT 乙级 1059
题目 题目地址:PAT 乙级 1059 题解 开始我是从暴力循环的角度考虑这道题,大概计算了一下时间复杂度应该不会超,但是很不幸没有通过,时间超限:之后考虑搜索算法可能优化不太好,因此就把输入的序列先 ...
- PAT 乙级 1044
题目 题目地址:PAT 乙级 1044 思路 简单的进制转化问题,根据题意进行相应的进制转化即可,因为题目已经划定了数据的求解范围,甚至连进制转化中的循环都不需要,进行简单计算就可以得出结果: 但本题 ...
- PAT 乙级 1078 / 1084
题目 PAT 乙级 1078 PAT 乙级 1084 题解 1078和1084这两道题放在一块写,主要是因为这两道题的解法和做题思路非常相似:之前我做这一类题没有一个固定的套路,想到哪写到哪,在某种程 ...
随机推荐
- FS2K人脸素描属性识别
人脸素描属性识别 代码:https://github.com/linkcao/FS2K_extract 问题分析 需要根据FS2K数据集进行训练和测试,实现输入一张图片,输出该图片的属性特征信息,提取 ...
- 图片64base转码与解码
场景一:图片转码成base64,传输,接收后解码成png等格式图片 import base64 # 读取图片,转换为base64编码格式 with open("F:\Archer\pictu ...
- Zabbix 5.0:通过LLD方式自动化监控阿里云RDS
Blog:博客园 个人 之前做了RDS监控,由于 RDS 实例梳理增多,手动添加的方式已经不够效率,故改为LLD(Low-level discovery)方式做监控. 什么是LLD LLD(Low-l ...
- 从解析HTML开始,破解页面渲染时间长难题
摘要:在本文中,将重点关注网页的初始渲染,即它从解析 HTML 开始. 我将探索可能导致高渲染时间的问题,以及如何解决它们. 本文分享自华为云社区<页面首屏渲染性能指南>,作者:Ocean ...
- Java对接拼多多开放平台API(加密上云等全流程)
前言 本文为[小小赫下士 blog]原创,搬运请保留本段,或请在醒目位置设置原文地址和原作者. 作者:小小赫下士 原文地址:Java对接拼多多开放平台API(加密上云等全流程) 本文章为企业ERP(I ...
- 5-4 Sentinel 限流_流控与降级
Sentinel 介绍 什么是Sentinel Sentinel也是Spring Cloud Alibaba的组件 Sentinel英文翻译"哨兵\门卫" 随着微服务的流行,服务和 ...
- IDEA快捷键之html篇-2
.qa-item .qa-item-ft .icon { display: inline-block; width: 16px; height: 16px; vertical-align: sub; ...
- nodejs学习总结02
response对象常用的API #response对象 response 对象类型<http.ServerResponse> response对象常用成员:response.write ...
- javascript引用奇趣
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 在win10系统环境下,安装配置sublime 3,构建python和vue.js开发环境(插件)
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_131 疫情当下,最近一直在用mac下的虚拟机运行win10系统,由于在线人数过多,直播授课的时候使用vscode的时候内存暴涨,于 ...