Assignments for the seventh Blue Bridge cup winter vacation and the seventh Blue Bridge cup

Source: Internet
Author: User

Assignments for the seventh Blue Bridge cup winter vacation and the seventh Blue Bridge cup

Reprinted please indicate the source: http://www.cnblogs.com/zhishoumuguinian/p/8365430.html
Winter vacation homework

At present, primary school mathematics is not so interesting. Look at this winter vacation assignment. Each square represents 1 ~ A number in column 13, but cannot be repeated.

□+ □= □
□- □= □
□×□= □
□Items □= □

For example: and:
6 + 7 = 13 7 + 6 = 13
9-8 = 1 9-8 = 1
3*4 = 12 3*4 = 12
10/2 = 5 10/2 = 5

Two solutions are supported. (The addition and multiplication exchange laws are different solutions.) How many solutions have you found? Enter an integer that represents the number of solutions. Note: You must submit an integer and do not enter any additional content or descriptive text.

 

This code is not commented out, but the idea is the same as the previous one. If you want to understand the idea, you can study this code. You can also take a look at my previous article titled "number of square fields in the seventh Blue Bridge Cup". Next, paste the code.

 

1 # include <iostream> 2 # include <algorithm> 3 # include <math. h> 4 5 using namespace std; 6 int a [4] [4], flag [14] = {0}; 7 int ans = 0; 8 9 bool Check (int x, int y, int I) 10 {11 if (y = 0) return true; 12 int tem; 13 switch (x) 14 {15 case tem = a [x] [y] + a [x] [Y-1]; 17 break; 18 case tem = a [x] [y]-a [x] [Y-1]; 20 break; 21 case tem = a [x] [y] * a [x] [Y-1]; 23 break; 24 case if (a [x] [Y-1] % a [x] [y]! = 0) 26 return false; 27 else tem = a [x] [Y-1]/a [x] [y]; 28 break; 29} 30 if (flag [tem] = 0 & tem> = 1 & tem <= 13) 31 {32 flag [tem] = 1; 33 a [x] [y + 1] = tem; 34 return true; 35} 36 else return false; 37} 38 39 void dfs (int x, int y) 40 {41 if (x = 4) 42 {43 ans ++; 44/* for (int I = 0; I <4; I ++) 45 {46 for (int j = 0; j <3; j ++) 47 {48 cout <a [I] [j] <""; 49} 50 cout <endl; 51} 52 cout <endl; * // * The comments are the numbers required to print the compound. */53 return; 54} 55 fo R (int I = 1; I <= 13; I ++) 56 {57 if (! Flag [I]) 58 {59 a [x] [y] = I; 60 flag [I] = 1; 61 bool check = Check (x, y, I ); 62 if (check) 63 {64 if (y = 0) 65 dfs (x, y + 1); 66 else67 dfs (x + 1, 0 ); 68} 69 if (check) 70 {71 flag [I] = 0; 72 flag [a [x] [y + 1] = 0; 73} 74 else75 flag [I] = 0; 76} 77 78} 79} 80 81 int main () 82 {83 dfs (0, 0); 84 cout <ans; 85 return 0; 86}

Answer:

If this article is helpful to you, please give it a try.

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.