If some sides have different squares, you can just spell a larger square, which is called the perfect square.
Historically, it took a long time to find a few perfect squares. For example: 22 squares with a length below
2 3 4 6 7 8 12 13 14 15 16 17 18 21 22 23 24 26 27 28 50 60
The combination of "figure 1.png" is a solution. At this time
Top Edge: 60 50
The bottom edge is: 26 28 17 21 18
The 22-step perfect Square is a total of 8. The following combination is another:
2 5 9 11 16 17 19 21 22 24 26 30 31 33 35 36 41 46 47 50 52 61
If you tell you that the scheme is close to the upper edge, it is from left to right: 47 46 61,
Can you figure out which squares are close to the bottom edge?
Please submit the side length of the square that clings to the lower edge, from left to right, separated by a space.
Do not fill in any superfluous content or explanatory text.
Search for a square edge length that finds a workable solution and outputs the last line
Read someone else's blog to know how to write
1#include <cstdio>2#include <cmath>3#include <iostream>4#include <cstring>5#include <algorithm>6 using namespacestd;7 intn,vis[ -];8 intD[] = {2,5,9, One, -, -, +, +, A, -, -, -, to, -, *, $, A, -, the, $, -, A};9 intg[155][155];Ten One //determine if a square with an edge length of n can be placed A BOOLInsideintXintYintN) - { - if(! (X+n <=155&& Y+n <=155)) the return false; - for(inti = X;i < n+x;i++) - for(intj = Y;j < n+y;j++) - if(G[i][j]) + return false; - return true; + } A at //put a square with a side length of n or take the square - //m==0 take away m==n place - voidFill (intXintYintNintm) - { - for(inti = X;i < n+x;i++) - for(intj = Y;j < n+y;j++) inG[I][J] =m; - } to + //find coordinates that can be placed - voidGet (int&x,int&y) the { * for(inti =1; I <=154; i++) $ for(intj =1; J <=154; j + +)Panax Notoginseng if(!G[i][j]) - { thex =i; +y =J; A return ; the } + } - $ //Check if the large square is full $ BOOLsolved () - { - for(inti =1; I <=154; i++) the for(intj =1; J <=154; j + +) - if(!G[i][j])Wuyi return false; the return true; - } Wu - BOOLDfsintXinty) About { $ if(Solved ()) - return true; - Else - { A Get (x, y); + for(intK =0; k < +; k++) the { - if(Inside (x,y,d[k])) $ { the if(!Vis[k]) the { the Fill (X,y,d[k],d[k]); theVIS[K] =1; - if(Dfs (x,y+D[k])) in return true; theFill (X,y,d[k],0); theVIS[K] =0; About } the } the Else the Break; + } - } the return false;Bayi } the the intMain () - { - //int a[30]; thememset (Vis,0,sizeof(Vis)); thememset (G,0,sizeof(G)); theFill (1,1, -, -); theFill (1, -, $, $); -Fill (1,94, A, A); theSort (d,d+ +); theDfs1,1); the 94 for(inti =1; I <=154; i++) thecout << g[154][i] <<' '; the the return 0;98}
"Blue Bridge Cup" sixth national game C language Group B 2. Perfect Square (DFS)