欢迎加入我们: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 ", i, node[i].val, node[i].next); 47 else 48 printf("%05d %d %05d ", i, node[i].val, node[i].next); 49 return 0; 50 }