当前位置:网站首页>CDZSC_ 2022 winter vacation personal training match level 21 (2)
CDZSC_ 2022 winter vacation personal training match level 21 (2)
2022-07-07 09:47:00 【moyangxian】
A
Answer key : Output n, 1, 2, 3, 4… that will do .
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
scanf("%d", &n);
printf("%d", n);
for (int i = 2; i <= n; i++)
printf(" %d", i - 1);
printf("\n");
}
signed main() {
int T;
scanf("%d", &T);
while (T--) solve();
return 0;
}
B
Answer key : First of all, it can be thought that the number of qualified people is very small , All in all 81 individual ; So directly enumerate these numbers to determine whether they are less than or equal to n that will do .
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 1; i <= 9; i++) {
int x = 0;
for (int j = 1; j <= 9; j++) {
x = x * 10 + i;
if (n >= x) ans++;
}
}
printf("%d\n", ans);
}
signed main() {
int T;
scanf("%d", &T);
while (T--) solve();
return 0;
}
C
Answer key : Imagine the process of moving the box to the right , such as :
4 2 Move right back –> 2 4
In fact, two numbers exchange positions , Then the answer is the array after sorting .
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
signed main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
if (i == 1) printf("%d", a[i]);
else printf(" %d", a[i]);
}
printf("\n");
return 0;
}
D
Answer key : Think in reverse , We can b Go to a To push , that b There are also two operations
- b Divide under the premise of even number 2
- b The last one is 1 Remove the last one under the premise of
These two operations are independent of each other , therefore b You can repeat these two operations until you can't operate or b<=a until , Finally, judge b Is it equal to a that will do .
#include<bits/stdc++.h>
using namespace std;
signed main() {
int a, b;
scanf("%d%d", &a, &b);
vector<int> ans;
while (b > a) {
if (b & 1) {
if (b % 10 == 1) {
b /= 10;
ans.push_back(10);
}
else break;
}
else {
b >>= 1;
ans.push_back(2);
}
}
reverse(ans.begin(), ans.end());
if (a == b) {
printf("YES\n");
printf("%d\n", ans.size() + 1);
printf("%d", a);
for (auto x : ans) {
if (x == 10) a = a * 10 + 1;
else a <<= 1;
printf(" %d", a);
}
}
else {
printf("NO\n");
}
return 0;
}
E
Answer key : You can determine a minimum value first , Then delete the number smaller than it, and the difference between the sum and the minimum value is greater than d The number of gets the answer . Take every number in the array as the minimum , The answer is the minimum .
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
signed main() {
int n, d;
scanf("%d%d", &n, &d);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
int ans = n;
for (int i = 1; i <= n; i++) {
int cnt = n - 1;
for (int j = i + 1; j <= n; j++)
if (a[j] >= a[i] && a[j] - a[i] <= d) cnt--;
ans = min(ans, cnt);
}
printf("%d\n", ans);
return 0;
}
F
Knowledge point : Binary understanding
Answer key : First of all, will n Into binary form , Remove from high to low , See if it can be disassembled n The sum of each bit of is equal to k, For example, the first example of the title :
9 4
9 --> 1001
sum( Sum of all digits ) = 2
1001 --> 0201
sum = 3
0201 --> 0121
sum = 4
0121 = 0 * 23 + 1 * 22 + 2 * 21 + 1 * 20
#include<bits/stdc++.h>
using namespace std;
const int N = 100;
int a[N], tot;
signed main() {
int n, k;
scanf("%d%d", &n, &k);
int sum = 0;
while (n) {
if (n & 1) sum++, a[++tot] = 1;
else a[++tot] = 0;
n >>= 1;
}
while (sum < k) {
if (tot == 1) break;
a[tot]--;
a[tot - 1] += 2;
sum++;
if (a[tot] == 0) tot--;
}
if (sum != k) printf("NO\n");
else {
printf("YES\n");
for (int i = 1; i <= tot; i++) {
for (int j = 1; j <= a[i]; j++)
printf("%d ", (1 << (i - 1)));
}
printf("\n");
}
return 0;
}
G
Answer key : First of all, we press odd and even numbers 1~n Split into two arrays , Output the odd array in reverse order , Even array even[0] and even[1] Change the order and then output .
for example :n = 11
odd : 1 3 5 7 9 11 —> 11 9 7 5 3 1
even : 2 4 6 8 —> 4 2 6 8
ans : 11 9 7 5 3 1 4 2 6 8
The answer is not unique , There are many construction methods on the Internet , Search for
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
scanf("%d", &n);
if (n < 4) {
printf("-1\n");
return;
}
else {
vector<int> odd, even;
for (int i = 1; i <= n; i += 2)
odd.push_back(i);
for (int i = 2; i <= n; i += 2)
even.push_back(i);
reverse(odd.begin(), odd.end());
for (int i = 0; i < odd.size(); i++)
printf("%d ", odd[i]);
printf("%d %d", even[1], even[0]);
for (int i = 2; i < even.size(); i++)
printf(" %d", even[i]);
printf("\n");
}
}
signed main() {
int T;
scanf("%d", &T);
while (T--) solve();
return 0;
}
边栏推荐
- liunx命令
- 洛谷P2482 [SDOI2010]猪国杀
- Information Security Experiment 1: implementation of DES encryption algorithm
- MongoDB怎么实现创建删除数据库、创建删除表、数据增删改查
- 进程间的通信方式
- CodeForces - 1324D Pair of Topics(二分或双指针)
- IIS redirection redirection appears eurl axd
- [bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
- C# Socke 服务器,客户端,UDP
- Communication mode between processes
猜你喜欢

Information Security Experiment 2: using x-scanner scanning tool

nlohmann json

Lesson 1: finding the minimum of a matrix

印象笔记终于支持默认markdown预览模式

战略合作|SubQuery 成为章鱼网络浏览器的秘密武器

Colorbar of using vertexehelper to customize controls (II)

20排位赛3

Unity uses mesh to realize real-time point cloud (I)

【原创】程序员团队管理的核心是什么?

How to speed up video playback in browser
随机推荐
剑指 Offer II 107. 矩阵中的距离
第一讲:寻找矩阵的极小值
ViewPager2和VIewPager的区别以及ViewPager2实现轮播图
【原创】程序员团队管理的核心是什么?
12、 Sort
Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
La différence entre viewpager 2 et viewpager et la mise en œuvre de la rotation viewpager 2
高斯消元
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
Gym - 102219J Kitchen Plates(暴力或拓扑序列)
Unity shader (to achieve a simple material effect with adjustable color attributes only)
2020浙江省赛
数据库多表关联查询问题
进程间的通信方式
第十四次试验
Unity shader (basic concept)
liunx命令
Thinkphp3.2 information disclosure
flinkcdc采集oracle在snapshot阶段一直失败,这个得怎么调整啊?
Kubernetes cluster capacity expansion to add node nodes