当前位置:网站首页>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;
}
边栏推荐
- Oracle安装增强功能出错
- Vs2013 generate solutions super slow solutions
- CMD startup software passes in parameters with spaces
- 有没有大佬帮忙看看这个报错,有啥排查思路,oracle cdc 2.2.1 flink 1.14.4
- How to become a senior digital IC Design Engineer (1-6) Verilog coding Grammar: Classic Digital IC Design
- Difference between process and thread
- 印象笔记终于支持默认markdown预览模式
- Main (argc, *argv[]) details
- How to use Mongo shake to realize bidirectional synchronization of mongodb in shake database?
- PostgreSQL创建触发器的时候报错,
猜你喜欢
JS reverse tutorial second issue - Ape anthropology first question
Install pyqt5 and Matplotlib module
Netease Cloud Wechat applet
如何使用clipboard.js库实现复制剪切功能
Impression notes finally support the default markdown preview mode
What development models did you know during the interview? Just read this one
CSDN salary increase technology - learn about the use of several common logic controllers of JMeter
Elaborate on MySQL mvcc multi version control
NATAPP内网穿透
Software modeling and analysis
随机推荐
H5网页播放器EasyPlayer.js如何实现直播视频实时录像?
PLC信号处理系列之开关量信号防抖FB
面试被问到了解哪些开发模型?看这一篇就够了
CSDN salary increase technology - learn about the use of several common logic controllers of JMeter
js逆向教程第二发-猿人学第一题
JMeter JDBC batch references data as input parameters (the simplest method for the whole website)
Flex flexible layout
软件建模与分析
sql 里面使用中文字符判断有问题,哪位遇到过?比如value&lt;&gt;`无`
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
Use 3 in data modeling σ Eliminate outliers for data cleaning
创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,且是随机赋值。同时,要求元素的值各不相同。
Communication mode between processes
Dynamics 365online applicationuser creation method change
Strategic cooperation subquery becomes the secret weapon of Octopus web browser
Impression notes finally support the default markdown preview mode
How to become a senior digital IC Design Engineer (5-2) theory: ULP low power design technology (Part 1)
Unity shader (data type in cghlsl)
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
其实特简单,教你轻松实现酷炫的数据可视化大屏