The 6th Lanqiao Cup Provincial Tournament C Language Group B Question Solution

The
number of tickets for the 6th Blue Bridge Cup Provincial Competition C Language Group B
Insert picture description here
:

The lottery numbers that need to be issued are from 10000-99999, but the condition is that these numbers cannot contain the number 4, and ask how many lottery tickets can be issued in total.

Ideas:

Split the number, write the judgment condition, and then run the loop from 10000 to 99999.

Code
method 1: Because the data is not large, enumerate directly with violence.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    int sum=99999-10000+1;//奖券总数目
    for(int i=10000;i<=99999;i++)//把每一位都枚举出来
    {
    
    
        int a=i/10000;
        int b=i%10000/1000;
        int c=i%1000/100;
        int d=i%100/10;
        int e=i%10;
        if(a==4||b==4||c==4||d==4||e==4)//写入判断条件
            sum--;
    }
    cout<<sum<<endl;
    return 0;
}
//答案52488

Method 2: Splitting for multi-digit numbers

#include<bits/stdc++.h>
using namespace std;
bool fun(int n)
{
    
    
    while(n)//把数字拆分
    {
    
    
     int x=n%10;
     if(x==4)//满足条件
   return true;
      n=n/10;
    }
}
int main()
{
    
    
     int sum=99999-10000+1;//奖券总数目
    for(int i=10000;i<=99999;i++)
    {
    
    
        if(fun(i))//满足条件
            sum--;
    }
    cout<<sum<<endl;
    return 0;
}

Galaxy bomb
Insert picture description here
method one:

I heard that you can use the calculator that comes with your computer. Just enter the time directly. Since the number of days that can only be entered is at most 999 days, you can do the calculation yourself if you exceed it.

Insert picture description here

Method Two:

Use an Excel spreadsheet, right click A and B, set to date mode, and then enter the date in A, enter =A1+1000 in B, and then enter.

Insert picture description here
Insert picture description here

The answer is 2017-08-05 (August 5, 2017)

Sanyang Xianrui
Insert picture description here
question meaning:

These characters are composed of different numbers from 0-9, and the characters composed of these numbers need to satisfy the equation in the question.

Idea 1:

Violent enumeration (the keyboard is expensive, and the number of lines of code is large)

Code

#include<bits/stdc++.h>
using namespace std;
//祥a;瑞b;生c;辉d;三e;羊f;献g;气h;
int main()
{
    
    
for(int a=1;a<=9;a++)
{
    
    for(int b=0;b<=9;b++)
{
    
    if(b==a)continue;
{
    
    for(int c=0;c<=9;c++)
{
    
    if(c==a||c==b)continue;
{
    
    for(int d=0;d<=9;d++)
{
    
    if(d==a||d==b||d==c)continue;
{
    
    for(int e=1;e<=9;e++)
{
    
    if(e==a||e==b||e==c||e==d)continue;
{
    
    for(int f=0;f<=9;f++)
{
    
    if(f==a||f==b||f==c||f==d||f==e)continue;
{
    
    for(int g=0;g<=9;g++)
{
    
    if(g==a||g==b||g==c||g==d||g==e||g==f)continue;
{
    
    for(int h=0;h<=9;h++)
{
    
    if(h==a||h==b||h==c||h==d||h==e||h==f||h==g)continue;
{
    
    if(a*1000+b*100+c*10+d+e*1000+f*100+g*10+b==e*10000+f*1000+c*100+b*10+h)
 cout<<e<<" "<<f<<" "<<g<<" "<<b<<endl;
}}}}}}}} }}}}}}}}
//答案:1 0 8 5

Idea two:

Full arrangement

Code

//全排列
#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    int a[10];
    for(int i=0;i<10;i++)
        a[i]=i;
    do{
    
    
        if(!a[0]||!a[4])continue;//每个数的第一位不能为0
        int x=a[0]*1000+a[1]*100+a[2]*10+a[3];
        int y=a[4]*1000+a[5]*100+a[6]*10+a[1];
        int z=a[4]*10000+a[5]*1000+a[2]*100+a[1]*10+a[7];
        if(x+y==z)
        cout<<x<<" "<<y<<" "<<z<<endl;
    }while(next_permutation(a,a+10));
}
//答案 1 0 8 5

Addition to multiplication
Insert picture description here
question meaning:

Add a string of numbers given in the question and change the two non-adjacent plus signs to make the result 2015.

Ideas:

Write a two-layer for loop in order to find out where the plus sign needs to be changed, and write a judgment condition in it.

Code

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    for(int i=1;i<=49;i++)
    {
    
    
    for(int j=i+1;j<=49;j++)
 {
    
    
  if(1225+i*(i+1)+j*(j+1)-(i+i+1+j+j+1)==2015)
    cout<<i<<" "<<j<<endl;
} }return 0;}
//答案10  27//16 24

The meaning of the number of card types
Insert picture description here
:

A deck of 52 cards is issued to four people, each with 13 cards. Regardless of suit, ask one person to deal with 13 cards. How many combinations are there?

Ideas:

There are a total of 13 types of cards, each of which has 4 cards. For each type of card, there are 5 cases to draw, and 0, 1, 2, 3, 4 cards are obtained. Use times to indicate the number of draws, and sum to indicate the number of cards in the hand. You must have times=13, and the card in your hand is also equal to 13, the number of combinations can be increased by 1

Method 1: Violence

Code

#include <iostream>
using namespace std;
int main()
{
    
    
int sum=0;
for(int a=0; a<=4; a++)
for(int b=0; b<=4; b++)
for(int c=0; c<=4; c++)
for(int d=0; d<=4; d++)
for(int e=0; e<=4; e++)
for(int f=0; f<=4; f++)
for(int g=0; g<=4; g++)
for(int h=0; h<=4; h++)
for(int i=0; i<=4; i++)
for(int j=0; j<=4; j++)
for(int k=0; k<=4; k++)
for(int l=0; l<=4; l++)
for(int m=0; m<=4; m++)
{
    
    if(a+b+c+d+e+f+g+h+i+j+k+l+m==13)
 sum++;}
cout<<sum<<endl;
 return 0;}
 //答案3598180

Method two: dfs

#include<bits/stdc++.h>
using namespace std;
int num=0;//统计方案次数
void dfs(int times,int sum)
{
    
    //times表示抽取次数,sum表示手中纸牌数量
    if(times>13||sum>13)//边界
    {
    
    
        return ;
    }
    if(times==13&&sum==13)//满足条件
     {
    
    
         num++;
         return ;
     }
     for(int i=0;i<5;i++)//每次抽取情况有五种,0,1,2,3,4张
     {
    
    
         sum+=i;
         dfs(times+1,sum);
         sum-=i;//回溯
     }
}
int main()
{
    
    
    dfs(0,0);
    cout<<num<<endl;
    return 0;
}
//答案3598180

Moving distance
Insert picture description here
Insert picture description here
question meaning:

According to the position of the number in the question, ask the distance between any two points.

Ideas:

Calculate the abscissa and ordinate of the two input points, and then subtract them. The horizontal and vertical coordinates need to be written according to the situation, depending on the code.

Code

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
    int w,m,n;
    while(cin>>w>>m>>n)
    {
    
    
        int x1,x2,y1,y2;
        x1=m%w==0?m/w:m/w+1;
        x2=n%w==0?n/w:n/w+1;
        y1=x1%2==0?m-(x1-1)*w:x1*w-m+1;
        y2=x2%2==0?n-(x2-1)*w:x2*w-n+1;
    cout<<abs(x1-x2)+abs(y1-y2)<<endl;
    }return 0;
}

I don’t know how to do the next two programming, ask the boss to teach me

If you think the writing is good, please like it! Than heart

Guess you like

Origin blog.csdn.net/m0_46669450/article/details/115329519