2015 6th Blue Bridge Cup Java Programming Undergraduate Group B Final Five-star Fill in the Number (Fill in the Results)

2015 6th Blue Bridge Cup Java Programming Undergraduate Group B Final Individual Problem Solution Summary:

https://blog.csdn.net/daixinliangwyx/article/details/90051040

 

Question 2

Title: Fill in the numbers with five stars

As shown in [Figure 1.png], the five-star pattern node is filled with numbers: 1~12, except 7 and 11.
The sum of the numbers on each line is required to be equal.

The picture is the correct way to fill it.

Please use the computer to search for all possible ways to fill in.
Note: The same filling method is calculated after rotating or mirroring.

Please submit an integer representing the number of proposals and nothing else.


Solution: Number each point on the five-pointed star and then fill in the first arrangement (the first arrangement of all arrangements) in the order of numbers from small to large, and then use the full arrangement function to judge whether the five lines are equal. As for deduplication, Because there will be no overlapping points before and after the rotated and mirrored folded, one arrangement scheme will have 10 representations (5 rotations, and 2 mirrored folds for each rotation, so it is 5* 2=10 kinds), the answer is the total result divided by 10.

Code:

#include<bits/stdc++.h>
using namespace std;
int num[10] = {1, 2, 3, 4, 5, 6, 8, 9, 10, 12};
int main() {
  int sum = 0;
  do {
    if(num[1]+num[2]+num[3]+num[4] == num[0]+num[2]+num[5]+num[8] &&
        num[1]+num[2]+num[3]+num[4] == num[0]+num[3]+num[6]+num[9] &&
        num[1]+num[2]+num[3]+num[4] == num[1]+num[5]+num[7]+num[9] &&
        num[1]+num[2]+num[3]+num[4] == num[4]+num[6]+num[7]+num[8]) sum++;
  } while (next_permutation(num, num+10));
  cout << sum / 10 << endl;
  return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326521480&siteId=291194637