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这两道题放在一块写,主要是因为这两道题的解法和做题思路非常相似:之前我做这一类题没有一个固定的套路,想到哪写到哪,在某种程 ...
随机推荐
- React技巧之循环遍历对象
原文链接:https://bobbyhadz.com/blog/react-loop-through-object 作者:Borislav Hadzhiev 正文从这开始~ 遍历对象的键 在React ...
- 关于nginx 和 uwsgi
关于nginx和uWSGI和Django之间的关系,我觉得要理一下. 原文链接 为什么要用nginx 因为我们要使用https协议访问.(y总说django不支持,但是我查了一下,django也可以支 ...
- 基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...
- Redis主从复制+Keepalived+VIP漂移实现HA高可用技术之详细教程
1.大家可以先看我的单台Redis安装教程,链接在此点击Redis在CentOS for LInux上安装详细教程 2.第一台redis配置,是正常配置.作为MASTER主服务器,第二台redis的配 ...
- 类似Tower的而故事还没结束
我对于SaaS一种有一种英雄主义的情怀在里面,无论是早期的推事本,还是后面我去调研的麦客CRM,国内的SaaS都在努力生长,在后疫情时代剩下的都是平台级的钉钉.飞书,或者垂直领域的王炸app了. 我早 ...
- The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
- CMP0065警告问题
参考链接: https://cmake.org/cmake/help/latest/policy/CMP0065.html https://cmake-developers.cmake.narkive ...
- CF1706A Another String Minimization Problem 题解
题意 给定一个长度为 \(n\) 的序列 \(a\) 以及一个长度为 \(m\) 的字符串 \(s\),初始 \(s\) 均为 \(\text{B}\),第 \(i\) 次操作可以把 \(s_{a_i ...
- CF1593D2 Half of Same
题目大意: 给定一个包含 \(n\)(\(n\) 是偶数)个整数的数列 \(a_1,a_2,\ldots,a_n\). 考虑一个可能的正整数 \(k\),在每次操作中,你可以选定一个 \(i\),并将 ...
- 浮点数(UVa11809)题解
浮点数(UVa11809)题解 如题 计算机常用阶码-尾数的形式保存浮点数.如下所示,若阶码有6位,尾数有8位,可以表达的最大的浮点数为0.1111111112 * 2 ^ 1111112.注意小数点 ...