当前位置:网站首页>[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
边栏推荐
- Image attribute of input: type attribute of fashion cloud learning -h5
- 梳理网络IP代理的几大用途
- Web17——EL与JSTL的使用
- ZigBee CC2530 minimum system and register configuration (1)
- [vulnhub range] - DC2
- Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
- 梳理網絡IP代理的幾大用途
- 如何防止网站被黑客入侵篡改
- Basic software testing Day2 - Case Execution
- SynchronousQueue 源码解析
猜你喜欢
梳理网络IP代理的几大用途
Dialogue with Bruce, author of PostgreSQL: "changing careers" is to better move forward
Analysis of InnoDB execution process in MySQL
Trier les principales utilisations de l'Agent IP réseau
[daily question] chessboard question
解锁OpenHarmony技术日!年度盛会,即将揭幕!
大家帮我看一下这是啥情况,MySQL5.5的。谢了
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
标签与路径
风尚云网学习-h5的input:type属性的image属性
随机推荐
【微信小程序】z-index失效
洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
Zero trust in network information security
Buuctf Web [bjdctf2020] zjctf, but so
SQLserver怎么插入或更新当天的星期数,bit而不是文本
实现一个盒子在父盒子中水平垂直居中的几种“姿势”
万事有你 未来可期 | ONES 2022校园招聘正式开启
Buuctf Web [gxyctf2019] no dolls
Trier les principales utilisations de l'Agent IP réseau
How to prevent the website from being hacked and tampered with
Qt进程间通信
AD20补充笔记3—快捷键+持续更新
NPDP|产品经理如何做到不会被程序员排斥?
Can I take the CPDA data analyst certificate for 0 foundation
力扣刷题之完全二叉树的节点个数
4.DRF 权限&访问频率&过滤&排序
消息队列概述
Basic software testing Day2 - Case Execution
Recommended programming AIDS: picture tool snipaste
NPDP | how can product managers not be excluded by programmers?