当前位置:网站首页>[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
2022-04-23 12:42:00 【Pan Daoxi】
List of articles
Preface
I took part in the Blue Bridge Cup competition these two days , Won the second prize in the city competition ( Average in the exam , Only more than 76% Classmate ), Enter the provincial competition . I'm in 4 month 23 Japan ( Saturday ) The game , So do it in advance 4 month 17 Day's problem brushing work , Let's make do with it , After I finish the exam, I will share my exam experience with you .
Brush problem , Walk up
There are several questions , Let's have a look , If there is anything wrong, please point it out !
Programming to realize : Compare the size
Title Description :
Given two positive integers N and M(0<N<200,0<M<200,N≠M), Compare the size of two positive integers , Then output a larger positive integer .
for example :N=145,M=100, After comparison 145 Greater than 100, Therefore, the output 145.
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
cout<<(n>m?n:m);
return 0;
}
Programming to realize : Factoring integer
Title Description :
Given a positive integer N, And then N Decompose into 3 Sum of positive integers . Calculate how many decomposition methods meet the requirements .
requirement :
1) Disintegrated 3 Positive integers are different ;
2) Disintegrated 3 None of the positive integers contain numbers 3 and 7.
Such as :N by 8, Decomposable into (1,1,6)、(1,2,5)、(1,3,4)、(2,2,4)、(2,3,3), Among them, the decomposition methods that meet the requirements are 1 Kind of , by (1,2,5).
Too lazy to write deep search ( Be lazy , Another one is a little confused ),
Direct loop , Simulation algorithm , Others may look a little ridiculous ..
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
int n,sum=0;
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=n;k++){
if(i+j+k==n){
if(i!=3&&j!=3&&k!=3&&i!=7&&j!=7&&k!=7&&i!=j&&i!=k&&j!=k&&i<j&&j<k){
//cout<<i<<" "<<j<<" "<<k<<endl;
sum++;
}
}
}
}
}
cout<<sum;
return 0;
}
Programming to realize : Combine ( To think about )
Prompt information : Factor : A factor is an integer a Divide by an integer b(b≠0) The quotient of is exactly an integer without a remainder , We said b yes a The factor of .
The common factor : Given a number of integers , If there is a ( some ) Numbers are their common factor , So this ( some ) Numbers are called their common factors .
Reciprocal number : The common factor is only 1 Two nonzero natural numbers of , It's called coprime number ; for example :2 and 3, The common factor is only 1, Coprime number . Title Description :
A shop packs a kind of candy into N and M Two specifications to sell (N and M Coprime number , And N and M There are countless bags ). This way of selling will limit the number of sweets that can't be bought . Then give N and M Value , Please calculate the maximum number of candy you can't buy .
for example :
When N=3,M=5,3 and 5 Coprime number , The number of sweets you can't buy is 1,2,4,7, The maximum amount of candy you can't buy is 7,7 Any amount of candy can be purchased through combination .
Look, it's troublesome , Ah ah !!!
I won't gather , Not exhaustive , This ……
I made a wave on the Internet , I have referred to Blog users Aikoin The article , You can have a look at , These are the main words :
There is a conclusion to this problem that can be used directly : Two coprime numbers a、b The maximum number of combinations of is ab-a-b. Detailed proof is given below ( Reference resources ):
If there is a foundation of Discrete Mathematics , We know that we can divide all nonnegative integers into a A model a Congruence equivalence class , Write it down as [0],[1],[2],…,[a-1], Respectively ak,ak+1,ak+2,…,ak+(a-1),(k∈Z).b The multiples of must be distributed here a In an equivalent class , Again because gcd(a,b)=1, So every equivalence class has b Multiple , And evenly distributed ( I can't figure it out here. I can draw two numbers by myself , That makes sense ). Special ,ab∈[0]. set up bKi Is an equivalence class [i] The smallest of all b Multiple , Then in the equivalence class bKi All numbers after can be expressed as ax+bKi, It must be combined . obviously , maximal bKi All subsequent integers can be combined , And to find the maximum number of combinations , We just need to consider the biggest bKi The numbers in front of you can . Put all the bKi List , Yes {0,b,2b,…,(a-1)b}. Obviously (a-1)b Is the biggest bKi, And in others a-1 In an equivalent class , There must be a number smaller than it and can be combined , These numbers are (a-1)b-1,(a-1)b-2,…,(a-1)b-(a-1). So the maximum number that cannot be combined is (a-1)b-a, namely ab-a-b.
For the sake of understanding , I take 4、7 As an example, draw a chart , Combined with the chart, it should be easy to understand the above proof process :
Don't ask me if I understand this long passage , I don't understand either , Look at this form ? This needs us to study . First post the code here :
// Author:PanDaoxi
#include <iostream>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
cout<<m*n-m-n;
return 0;
}
Refer to the answer
The first question is
#include <iostream>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
cout << max(n,m) << endl;
// Mode two if...else
// Mode three Three wood operators
return 0;
}
The second question is
#include <iostream>
using namespace std;
int n, ans;
bool isSame(int x,int y,int z){
// No one can be 3,7
if(x==3||x==7||y==3||y==7||z==3||z==7)
return false;
// Two cannot be equal
if(x == y || x == z || y == z)
return false;
return true;
}
int main(){
cin >> n;
for(int i = 1;i < n;i++){
for(int j = 1;j < n;j++){
if(n-i-j > 0 && isSame(i,j,n-i-j)){
ans++;
}
}
}
cout << ans / 6; //3 The digits are arranged in full order 6 In this case , Need to get rid of
return 0;
}
Third question ( no )
版权声明
本文为[Pan Daoxi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231239347137.html
边栏推荐
- Plato Farm-以柏拉图为目标的农场元宇宙游戏
- Lesson 25 static member variables of classes
- bert-base-chinese下载(智取)
- Deploying MySQL in cloud native kubesphere
- Why is the premise of hash% length = = hash & (length-1) that length is the nth power of 2
- BUUCTF WEB [GXYCTF2019]禁止套娃
- Analysis of InnoDB execution process in MySQL
- Use source insight to view and edit source code
- One way ANOVA of SPSS
- Basic software testing Day2 - Case Execution
猜你喜欢
leetcode:437. 路径总和 III【dfs 选还是不选?】
Outsourcing for five years, abandoned
大家帮我看一下这是啥情况,MySQL5.5的。谢了
ZigBee CC2530 minimum system and register configuration (1)
没有空闲服务器?导入 OVF 镜像快速体验 SmartX 超融合社区版
Worder font page font comparison table
基于卷积神经网络的遥感影像分类识别系统
Number of nodes of complete binary tree
bert-base-chinese下载(智取)
Object.keys后key值数组乱序的问题
随机推荐
SQL exercise (I)
Kubernets Getting started tutoriel
对话PostgreSQL作者Bruce:“转行”是为了更好地前行
SSL证书退款说明
Metalama简介4.使用Fabric操作项目或命名空间
Outsourcing for five years, abandoned
STM32控制步进电机(ULN2003+28byj)
Plato Farm-以柏拉图为目标的农场元宇宙游戏
STM32 control stepper motor (ULN2003 + 28byj)
Jiachen chapter Genesis "inner universe" joint Edition
Use source insight to view and edit source code
How to solve the computer system card?
洛谷P3236 [HNOI2014]画框 题解
使用Source Insight查看编辑源代码
QT draw text
uni-app 原生APP-云打包集成极光推送(JG-JPUSH)详细教程
At instruction of nbiot
【微信小程序】z-index失效
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
0基础可以考CPDA数据分析师证书吗