当前位置:网站首页>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;
}
边栏推荐
- Netease Cloud Wechat applet
- NATAPP内网穿透
- 小程序实现页面多级来回切换支持滑动和点击操作
- 根据热门面试题分析Android事件分发机制(二)---事件冲突分析处理
- 2020CCPC威海 J - Steins;Game (sg函数、线性基)
- CDZSC_2022寒假个人训练赛21级(1)
- Natapp intranet penetration
- Arthas simple instructions
- Esp8266 uses TF card and reads and writes data (based on Arduino)
- Unity shader (learn more about vertex fragment shaders)
猜你喜欢
ComputeShader
Use 3 in data modeling σ Eliminate outliers for data cleaning
Vs2013 generate solutions super slow solutions
Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
Oracle installation enhancements error
esp8266使用TF卡并读写数据(基于arduino)
Unity shader (basic concept)
What development models did you know during the interview? Just read this one
Impression notes finally support the default markdown preview mode
Deep understanding of UDP, TCP
随机推荐
Information Security Experiment 3: the use of PGP email encryption software
Natapp intranet penetration
CDZSC_2022寒假个人训练赛21级(2)
The difference between viewpager2 and viewpager and the implementation of viewpager2 in the rotation chart
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用
# Arthas 简单使用说明
esp8266使用TF卡并读写数据(基于arduino)
La différence entre viewpager 2 et viewpager et la mise en œuvre de la rotation viewpager 2
AI从感知走向智能认知
Scratch crawler mysql, Django, etc
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
有没有大佬帮忙看看这个报错,有啥排查思路,oracle cdc 2.2.1 flink 1.14.4
Oracle安装增强功能出错
沙龙预告|GameFi 领域的瓶颈和解决方案
印象笔记终于支持默认markdown预览模式
Unity uses mesh to realize real-time point cloud (II)
Communication mode between processes