2015 The sixth session of the Blue Bridge Cup (self-understood topic)

Source: Internet
Author: User

1. Question Description: Number of Lotteries

Some people are superstitious figures, such as the number with "4", Think and "dead" homophonic, feel unlucky.

Although these statements are nonsense, they sometimes have to cater to the needs of the public. The lottery number for a lottery is 5 digits (10000-99999),

Ask not to appear with "4" of the number, the organizer please calculate, if any two lottery tickets are not heavy, the maximum number of tickets can be issued.

Please submit this number (an integer), do not write any superfluous content or descriptive text.

Idea: 5 cycles, the first weight is 1-9, the rest is 0-9 (so you can traverse all the numbers from 10000 to 99999), and the judging condition for each variable cannot be 4.

Results: 52488

Code:

#include <iostream>using namespace Std;int main () {int a,b,c,d,e;int count1=0;for (a=1;a<=9;a++) {for (b=0;b <=9;b++) {for (c=0;c<=9;c++) {for (d=0;d<=9;d++) {for (e=0;e<=9;e++) {if (a!=4&&b!=4&&c!=4 &&e!=4&&d!=4) count1++;}}}} Cout<<count1<<endl;return 0;}


2. Problem Description: Galaxy Bomb

In the vast space of the X galaxy, many X-star man-made "bombs" were floated to serve as signposts in the universe.

Each bomb can be set to explode after a few days.

For example: The Alpha bomb was placed on January 1, 2015 and timed for 15 days, then it exploded on January 16, 2015.

There is a beta bomb, placed on November 9, 2014, timed for 1000 days, please calculate the exact date it exploded.

Please fill in the date in the format YYYY-MM-DD the 4-bit year 2-digit month 2-bit date. For example: 2015-02-19

Please write strictly in the format. No other text or symbols can appear.

Idea: This problem, I do not program, but the hand calculation. Known current date is 2014-11-09, timing is 1000 days, 2015 is not leap year, 1000-365=635, date is 2015-11-09, 2016 is leap year (can be divisible by 4 but not divisible by 100), 635-366 = 269, the date is 2016-11-09;266 less than one year, so next by the month to do subtraction, November 30 days, December 31 days, January 31 days, February 28 days, March 31 days, April 30 days, May 31 days, June 30 days, July 31 days, 269-30-31-31-28-31-30-31-30=27, the date is 2017-07-09;27-22=5 and the date is 2017-07-31; the last date is 2017-08-05.


3. Description of the problem: three sheep for the Rui

Observe the following addition calculation:

The auspicious omen is shining
+ Three sheep offering Rui
-------------------
San Yang Sheng Bling

Among them, the same Chinese characters represent the same numbers, and the different Chinese characters represent different numbers.

Please fill in the 4-digit number (the answer is the only) represented by "San Yang Rui", do not fill in any superfluous content.

Idea: To see this problem, the first reaction is how many different words will be controlled by a few heavy loops, the judgment condition in the loop is two four digits and equal to a five-digit number.

Results: 1085

Code:

#include <iostream>using namespace Std;int main (int argc, char *argv[]) {int a,b,c,d,e,f,g,h;//stands for: Xiang, Rui, Sheng, Hui, san, lamb, offering , Gas int sum1=0,sum2=0,sum=0;//sub-table represents: Auspicious, three sheep, three sheep bling for (a=1;a<=9;a++)//starting from 1, because the first digit can not be 0 for (b=0;b<=9;b++) fo R (c=0;c<=9;c++) for (d=0;d<=9;d++) for (e=1;e<=9;e++)//starting from 1, because the number first cannot be 0 for (f=0;f<=9;f++) for (g=0;g<=9 ; g++) for (h=0;h<=9;h++) {if (a!=b&&a!=c&&a!=d&&a!=e&&a!=f&&a!=g& &a!=h && b!=c&&b!=d&&b!=e&&b!=f&&b!=g&&b!=h && c!=d& Amp;&c!=e&&c!=f&&c!=g&&c!=h && d!=e&&d!=f &&d!=g&&d!=  H && e!=f&&e!=g&&e!=h && f!=g&&f!=h && g!=h) {sum1=a*1000 + b*100 + c*10 + d;sum2=e*1000 + f*100 + g*10 + b;sum = e*10000 + f*1000 + c*100 + b*10 + h;if (sum1+sum2 = = sum) {cout<<e<<f& Lt;<g<<b;}}} Cout<<endl;return 0;}

5. Problem Description: Nine array fractions

1,2,3...9 These nine numbers make up a fraction with a value of exactly 1/3, how does the group method work?

The following program implements this function, please fill in the missing code in the underlined section.
#include <stdio.h>
void Test (int x[])
{
int a = x[0]*1000 + x[1]*100 + x[2]*10 + x[3];
int b = x[4]*10000 + x[5]*1000 + x[6]*100 + x[7]*10 + x[8];

if (a*3==b) printf ("%d/%d\n", A, b);
}
void f (int x[], int k)
{
int i,t;
if (k>=9) {
Test (x);
Return
}
for (i=k; i<9; i++) {
{t=x[k]; x[k]=x[i]; x[i]=t;}
f (x,k+1);
_____________________________________________//Fill in the blanks
}
}
int main ()
{
int x[] = {1,2,3,4,5,6,7,8,9};
f (x,0);
return 0;
}

Note: Fill in only what is missing, and do not write any existing code or descriptive text on any of the surfaces.

Idea: This question, please forgive me is blindfolded, did not expect to.

Result: {t=x[k]; x[k]=x[i]; x[i]=t;}


6. Problem Description: Addition variable multiplication

We all know: 1+2+3+ ... + 49 = 1225

You are now asked to turn two of these nonadjacent plus signs into multiplication sign, making the result 2015

Like what:

1+2+3+...+10*11+12+...+27*28+29+...+49 = 2015

Is the answer that meets the requirements.

Please look for another possible answer and submit the number to the left of the front multiplication sign (for example, commit 10).

Note: You are required to submit an integer, do not fill in any superfluous content.

Idea: First of all 1-49 and divided into 5 parts, sum1,pro1,sum2,pro2,sum3,sum representative and, pro represents the product. There are 3 cases of sum1: I*2;2*3;3*4, so sum1=0;sum1=1;sum1= (1+2) *2/2=3. Pro1 always only one situation, is pro1=i* (i+1). SUM2 also has three cases, j-i=2 (that is, there is only one + between two *), j-i=3 (that is, there are 2 + between two *), j-i>3 (that is, two * has >2 +), so sum2=0;sum2=j-1,;sum2= (i+j+1) * ( J-I-2)/2. Pro2 always only one situation, is j* (j+1). Sum3 I did not consider that the default number of entries will always >2,sum3= (j+51) * (48-J)/2. (In fact, sum3 can also be divided into, when the last no item, only 1 items, >1; then sum3=0,;sum3=49;sum3= (j+51) * (48-J)/2) with I and J control two loops.

Results: 16 out of two cases 10,27;16,24

Code:

#include <iostream>using namespace Std;int main () {int i=0,j=0;int sum1=0,sum2=0,sum3=0;int pro1,pro2;for (i=1;i <=46;i++)//The maximum value for this I should be 46, but to 48 there is no error {if (i==1) sum1=0;if (i==2) sum1=1;if (i!=1 && i!=2) sum1=i* (i-1)/2;//sum1 = (1+i-1) * (i-1-1+1)/2;pro1 = i* (i+1), for (j=i+2;j<=48;j++)//Because two nonadjacent + numbers are changed to *, so J has recently also been counted from i+2 {if (j-i<=2) {sum2=0; pro2=j* (j+1); sum3= (j+51) * (48-j)/2;//sum3= (j+2+49) * (49-j-2+1)/2;} else if (j-i==3) {sum2=j-1;pro2=j* (j+1); sum3= (j+51) * (49-j)/2;//sum3= (j+2+49) * (49-j-2+1)/2;} Else{sum2= (i+j+1) * (j-i-2)/2;//sum2= (i+2+j-1) * (j-1-i-2+1)/2;pro2=j* (j+1); sum3= (j+51) * (48-j)/2;//sum3= (j+2+49) * ( 49-J-2+1)/2;} if (sum1 + Pro1 + sum2 + pro2 + sum3 = =) cout<<i << "" <<j<<endl;}} return 0;}

2015 The sixth session of the Blue Bridge Cup (self-understood topic)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.