当前位置:网站首页>CDZSC_ 2022 winter vacation personal training match level 21 (1)
CDZSC_ 2022 winter vacation personal training match level 21 (1)
2022-07-07 09:48:00 【moyangxian】
A
The question : A little
Answer key : take n Divide the sum of the numbers by n that will do .
#include<bits/stdc++.h>
using namespace std;
signed main(){
int n;
scanf("%d", &n);
int sum = 0;
for(int i = 1; i <= n; i++){
int x;
scanf("%d", &x);
sum += x;
}
printf("%.10f\n", sum * 1.0 / n);
return 0;
}
B
The question : A little
Answer key : Since the minimum value is required , So give priority to large denomination money .
#include<bits/stdc++.h>
using namespace std;
int a[] = {
100, 20, 10, 5, 1};
signed main(){
int n;
scanf("%d", &n);
int ans = 0;
for(int i = 0; i < 5; i++){
ans += n / a[i];
n %= a[i];
}
printf("%d\n", ans);
return 0;
}
C
The question : A little
Knowledge point :STL Application
Answer key : Splice the string with yourself , Equivalent to length times 2; for example :abcd -> abcdabcd
Then take out each one with a length of len( The length of the original string ) String , use map Just record it .
#include<bits/stdc++.h>
using namespace std;
map<string, int> mp;
signed main(){
string s;
cin >> s;
int len = s.length();
s += s;
int ans = 0;
for(int i = 0; i < len; i++){
string t = s.substr(i, len);
if(mp[t] == 0) ans++;
mp[t]++;
}
printf("%d\n", ans);
return 0;
}
D
The question : A little
Answer key : because 6 = 2 * 3, So take a ride 2 except 6 The operation of is equivalent to dividing by 3, So the operation turns into a one-step operation to n Divide 6 Or two steps will n Divide 3, If n It cannot be changed into 1 There is no solution. .
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n;
scanf("%d", &n);
int ans = 0;
while(true){
if(n % 6 == 0){
n /= 6;
ans++;
}
else if(n % 3 == 0){
n /= 3;
ans += 2;
}
else{
break;
}
}
if(n == 1) printf("%d\n", ans);
else printf("-1\n");
}
signed main(){
int T;
scanf("%d", &T);
while(T--) solve();
return 0;
}
E
The question : A little
Answer key : Choose the smallest number each time to subtract , It is equivalent to subtracting each number after arranging the array in order , And if a number appears many times, it will only be subtracted once . For each of these a[i] for , The array subtracts the difference between it and the previous one , namely a[i] - a[i - 1]
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
signed main(){
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
n = unique(a + 1, a + 1 + n) - a - 1;
for(int i = 1; i <= k; i++){
if(i <= n) printf("%d\n", a[i] - a[i - 1]);
else printf("0\n");
}
return 0;
}
F
The question : A little
Answer key : If n The sum of the numbers is not 0, Then I will n The number can be divided into one section . If n The sum of the numbers is 0, Then find the last not for 0 Number of numbers ( Subscript to be pos), take (1,pos - 1) Divide into sections ,(pos, n) It can be divided into sections .
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
signed main(){
int n;
scanf("%d", &n);
int sum = 0;
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
sum += a[i];
}
if(sum){
printf("YES\n");
printf("1\n");
printf("1 %d\n", n);
}
else{
int pos = -1;
for(int i = 1; i <= n; i++)
if(a[i]) pos = i;
if(pos == -1) printf("NO\n");
else{
printf("YES\n");
printf("2\n");
printf("1 %d\n", pos - 1);
printf("%d %d\n", pos, n);
}
}
return 0;
}
G
The question : A little
Answer key : Because the array finally forms an arithmetic sequence , We can enumerate a[1] You can know the value of the entire array , Compare the obtained array with the original array , Record the number of different numbers , The answer is the optimal solution .
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int a[N], b[N], t[N];
signed main(){
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
int ans = n;
for(int i = 1; i <= 1000; i++){
b[1] = i;
int cnt = 0;
for(int j = 1; j <= n; j++){
b[j] = b[1] + (j - 1) * k;
if(b[j] != a[j]) cnt++;
}
if(cnt < ans){
memcpy(t, b, sizeof(b));
ans = cnt;
}
}
printf("%d\n", ans);
for(int i = 1; i <= n; i++){
if(t[i] > a[i]) printf("+ %d %d\n", i, t[i] - a[i]);
else if(t[i] < a[i]) printf("- %d %d\n", i, a[i] - t[i]);
}
return 0;
}
边栏推荐
- 根据热门面试题分析Android事件分发机制(二)---事件冲突分析处理
- Can't connect to MySQL server on '(10060) solution summary
- Oracle installation enhancements error
- Thinkphp3.2 information disclosure
- Upload taro pictures to Base64
- 大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
- In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
- **grafana安装**
- 农牧业未来发展蓝图--垂直农业+人造肉
- How to become a senior digital IC Design Engineer (5-2) theory: ULP low power design technology (Part 1)
猜你喜欢

Unity shader (to achieve a simple material effect with adjustable color attributes only)

網易雲微信小程序

第一讲:寻找矩阵的极小值

如何使用clipboard.js库实现复制剪切功能

nlohmann json
![[4g/5g/6g topic foundation-146]: Interpretation of white paper on 6G overall vision and potential key technologies-1-overall vision](/img/fd/5e8f74da25d9c5f7bd69dd1cfdcd61.png)
[4g/5g/6g topic foundation-146]: Interpretation of white paper on 6G overall vision and potential key technologies-1-overall vision

农牧业未来发展蓝图--垂直农业+人造肉

其实特简单,教你轻松实现酷炫的数据可视化大屏

Netease Cloud Wechat applet

First issue of JS reverse tutorial
随机推荐
沙龙预告|GameFi 领域的瓶颈和解决方案
章鱼未来之星获得25万美金奖励|章鱼加速器2022夏季创业营圆满落幕
Niuke - Huawei question bank (61~70)
flinkcdc 用sqlclient可以指定mysqlbinlog id执行任务吗
Liunx command
Thinkphp3.2 information disclosure
CodeForces - 1324D Pair of Topics(二分或双指针)
Write VBA in Excel, connect to Oracle and query the contents in the database
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
Flex flexible layout
【BW16 应用篇】安信可BW16模组/开发板AT指令实现MQTT通讯
CDZSC_2022寒假个人训练赛21级(1)
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
NETCORE 3.1 solves cross domain problems
JS judge whether checkbox is selected in the project
iNFTnews | 时尚品牌将以什么方式进入元宇宙?
CDZSC_2022寒假个人训练赛21级(2)
Addition, deletion, modification and query of ThinkPHP database
Binary tree high frequency question type
[4g/5g/6g topic foundation -147]: Interpretation of the white paper on 6G's overall vision and potential key technologies -2-6g's macro driving force for development