欢迎加入我们: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乙级每日习题的更多相关文章

  1. C#版 - PAT乙级(Basic Level)真题 之 1021.个位数统计 - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - P ...

  2. PAT乙级真题及训练题 1025. 反转链表 (25)

    PAT乙级真题及训练题 1025. 反转链表 (25) 感觉几个世纪没打代码了,真是坏习惯,调了两小时把反转链表调出来了,心情舒畅. 这道题的步骤 数据输入,数组纪录下一结点及储存值 创建链表并储存上 ...

  3. PAT 乙级 1024

    题目 题目地址:PAT 乙级 1024 题解 模拟题,重点需要考虑到各种不同情况:简单来说一下: 因为输入格式固定,所以把不同的部分分别存储和处理可以在很大程度上简化运算:其中需要考虑最多的就是小数部 ...

  4. PAT 乙级 1017

    题目 题目地址:PAT 乙级 1017 题解 粗看是一道大数除法题,实际上只不过是通过字符数组模拟除法过程,理解之后还是比较简单的: 具体分析一下本题: 因为题设中的除数(n)是一位整数,因此大幅简化 ...

  5. PAT 乙级 1015

    题目 题目地址:PAT 乙级 1015 题解 常规题,难点在于理清楚排序规则,通过比较简洁的方式进行编码: 在这里我选择使用vector进行存储,并使用sort方法排序,因为本题不是简单按照大小排序, ...

  6. PAT 乙级 1003

    题目 题目地址:PAT 乙级 1003 题解 规律观察题,本题的关键在于把题读懂,同时还有几个比较容易疏忽的地方需要注意:总之这道题要考虑的东西更多,细节上也要特别注意: 规律:“如果 aPbTc 是 ...

  7. PAT 乙级 1059

    题目 题目地址:PAT 乙级 1059 题解 开始我是从暴力循环的角度考虑这道题,大概计算了一下时间复杂度应该不会超,但是很不幸没有通过,时间超限:之后考虑搜索算法可能优化不太好,因此就把输入的序列先 ...

  8. PAT 乙级 1044

    题目 题目地址:PAT 乙级 1044 思路 简单的进制转化问题,根据题意进行相应的进制转化即可,因为题目已经划定了数据的求解范围,甚至连进制转化中的循环都不需要,进行简单计算就可以得出结果: 但本题 ...

  9. PAT 乙级 1078 / 1084

    题目 PAT 乙级 1078 PAT 乙级 1084 题解 1078和1084这两道题放在一块写,主要是因为这两道题的解法和做题思路非常相似:之前我做这一类题没有一个固定的套路,想到哪写到哪,在某种程 ...

随机推荐

  1. leetcode二叉树题目总结

    leetcode二叉树题目总结 题目链接:https://leetcode-cn.com/leetbook/detail/data-structure-binary-tree/ 前序遍历(NLR) p ...

  2. POI设置列宽 自动调整列宽

    for (int i = 0; i <= totalColumn; i++) { sheet.autoSizeColumn((short)i,true); //调整列宽 } 其中totalCol ...

  3. HTTP Status 405 - Request method 'GET' not supported?(尚硅谷Restful案例练习关于Delete方法出现的错误)

    哈罗大家好,最近在如火如荼的学习java开发----Spring系列框架,当学习到SpringMVC,动手实践RESTFUL案例时,发现了以上报错405,get请求方法没有被支持. 首先第一步,我查看 ...

  4. Learning Latent Graph Representations for Relational VQA

    The key mechanism of transformer-based models is cross-attentions, which implicitly form graphs over ...

  5. HashSet 添加/遍历元素源码分析

    HashSet 类图 HashSet 简单说明 HashSet 实现了 Set 接口 HashSet 底层实际上是由 HashMap 实现的 public HashSet() { map = new ...

  6. mesi--cpu内存一致性协议

    目录 cpu缓存一致性问题 mesi协议 mesi协议4种状态,及状态转换 模拟工具演示 cpu缓存一致性问题 一个服务器中有多个核,每个核中有多个cpu,每个cpu有多个线程.缓存最少分为3级,1级 ...

  7. Spring 核心概念

    Spring 核心概念 引言 本文主要介绍 Spring 源码中使用到的一些核心类 1. BeanDefinition BeanDefinition表示Bean定义,BeanDefinition 中存 ...

  8. Mysql 系列 | 日志模块

    了解了 SQL 执行的流程,知道每一条语句都经过连接器.查询存储.分析器.优化器.执行器最后到存储引擎的过程.查询语句是如此,更新语句也不例外. 不同的是,更新语句会修改表数据,这里就涉及到两个重要的 ...

  9. 算法竞赛进阶指南0x14 Hash

    组成部分: 哈希函数: 链表 AcWing137. 雪花雪花雪花 因为所需要数据量过于大,所以只能以O(n)的复杂度. 所以不可能在实现的过程中一一顺时针逆时针进行比较,所以采用一种合适的数据结构. ...

  10. python 操作pdf文档

    简介 在实际项目中,我们有可能需要提取当中的部分内容并导出,给PDF文件添加水印,合并多份PDF文件等等,而本文会着重用到PyPDF2模块来玩转PDF文档,以及tabula模块来对PDF文档中的表格数 ...