当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Dynamics 365Online ApplicationUser创建方式变更
Unity3d interface is embedded in WPF interface (mouse and keyboard can respond normally)
ComputeShader
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
Esp8266 uses TF card and reads and writes data (based on Arduino)
[4g/5g/6g topic foundation-146]: Interpretation of white paper on 6G overall vision and potential key technologies-1-overall vision
第一讲:包含min函数的栈
Lesson 1: finding the minimum of a matrix
First issue of JS reverse tutorial
Unity shader (to achieve a simple material effect with adjustable color attributes only)
随机推荐
H5网页播放器EasyPlayer.js如何实现直播视频实时录像?
Nested (multi-level) childrn routes, query parameters, named routes, replace attribute, props configuration of routes, params parameters of routes
Thinkphp3.2 information disclosure
创建一个长度为6的int型数组,要求数组元素的值都在1-30之间,且是随机赋值。同时,要求元素的值各不相同。
**Grafana installation**
esp8266使用TF卡并读写数据(基于arduino)
Unity shader (basic concept)
NATAPP内网穿透
软件建模与分析
牛客网——华为题库(61~70)
scrapy爬虫mysql,Django等
Install pyqt5 and Matplotlib module
Vs2013 generate solutions super slow solutions
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
Information Security Experiment 1: implementation of DES encryption algorithm
Lecture 1: stack containing min function
Oracle installation enhancements error
NETCORE 3.1 solves cross domain problems
战略合作|SubQuery 成为章鱼网络浏览器的秘密武器
Can flycdc use SqlClient to specify mysqlbinlog ID to execute tasks