# Blue Bridge Cup 31 day sprint punch in (Day3)

First question

Age coincidence

Xiao Ming went to the cinema with his cousin. Someone asked their age. Xiao Ming said: this year is our lucky year. The four digits of my year of birth add up to my age. So is my cousin's. It is known that this year is 2014, and Xiao Ming's age refers to one year old.

Please infer and fill in Xiao Ming's year of birth.

Analysis: it is known that the four digits of 2014 and the year of birth of Xiao Ming and his cousin add up to their respective ages (the sum of the four digits of Xiao Ming's year of birth = 2014 - year of birth, the same for his cousin), so we can use if to judge and output the results.! Note: there may be multiple data output. Of course, Xiao Ming will be bigger than his cousin. Cold joke: Xiao Ming should not be 100 years old, otherwise how can he take his cousin to the movies?

```#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main() {
for(int i=1914; i<=2014; i++) {
int s=0,j=i;
while(j) {
s+=j%10;
j/=10;
}
if(s==2014-i) cout<<i<<endl;
}
return 0;
}```

Of course, we can also calculate by simple mathematics that our cousin was born in 2008, and then change the for cycle condition to I < 2006 to get Xiaoming's year of birth.

Second question

Card triangle

A. A total of 9 Cards of 2,3,4,5,6,7,8,9 are arranged into an equilateral triangle (a is calculated as 1). The sum of each edge is required to be equal. The following figure is a layout.

There may be many such arrangements.

If we consider the same arrangement after rotation and mirror image, how many different arrangements are there?

Please calculate and submit this figure.

Analysis: we can understand the figure in the question as A96483752. Does it look a little familiar? you 're right! It is similar to 123456789 in our cognition, so this problem can be calculated by using the next_permutation function in C + +. In the question, it is said that the sum of each side should be equal (i.e. A+9+4+3=A+6+8+2=3+7+5+2). We can write the above form from top to bottom and from left to right. The title also said that "the same after rotation and mirror image is the same". We can obtain three kinds through rotation, and then obtain three kinds through their respective mirrors, a total of six kinds, so the total number is / 6.

```#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef long long LL;
int a[]={1,2,3,4,5,6,7,8,9};

bool judge() {
if(a[0]+a[1]+a[3]+a[5]==a[0]+a[2]+a[4]+a[8] && a[0]+a[2]+a[4]+a[8]==a[5]+a[6]+a[7]+a[8]) return true;
else return false;
}

int main() {
int s=0;
do {
if(judge()) //Determine whether each side is equal
s++;
}while(next_permutation(a,a+9));
cout<<s/6;
return 0;
}```

Question 3

Ball game

### Title Description

There are {n small balls in the box today. A and B take turns to take the balls from the box. Everyone can see how many balls the other person has taken and how many are left in the box. Both of them are very smart and won't make wrong judgments.

We agree:

The number of balls each person takes out of the box must be: 1, 3, 7 or 8. You can't abstain when it's a party's turn to take the ball! A take the ball first, and then take the ball alternately until it is finished. The side forced to get the last ball is the negative side (loser)

Please program to determine whether A can win for A specific initial number of balls without misjudgment on both sides?

### Enter description

The first is an integer n (n < 100), which means that there are n integers next.

Then there are n integers, each occupying one line (integer < 10 ^ 4), representing the initial number of balls.

### Output description

The program outputs n lines, indicating the winning or losing situation of A (0 for losing and 1 for winning).

Analysis: this problem is a simple game theory problem. In short, we can make ourselves enter a winning point through the situation. Similarly, the other party can make us enter a losing point. The amount of data in this problem is very small. We can do it by typing a table. Assuming that there is only one ball now, then this point is the must lose point of a; If there are two balls now, then a takes away one and leaves one to make B enter the winning point, that is to say, this point is the winning point of A. similarly, 4 balls, 8 balls and 9 balls are the winning points of A. a can make B enter the losing point by taking an appropriate number of balls. Therefore, we can deduce the winning point of a through the losing point of a (that is, add the number of balls a can take at one time to the losing point).

```#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;
int a[10005];

int main() {
memset(a,0,sizeof(a));//Custom reset
for(int i=1; i<=1000; i++)
if(a[i]==0) {
a[i+1]=1;
a[i+3]=1;
a[i+7]=1;
a[i+8]=1;
}//Play the table to store the victory. The amount of data in the question is 1e4, which is very small and direct
int n;
cin>>n;
for(int i=0; i<n; i++) {
int s;
cin>>s;
cout<<a[s]<<endl;
}
return 0;
}```

For the first time, I have many shortcomings. Please forgive me. One of your compliments is my driving force.

Keywords: C++ Algorithm

Added by foxfirediego on Wed, 09 Mar 2022 17:54:38 +0200