Topic Links:
Codeforces 201A
Main topic:
Give an X, to find a square matrix of the smallest side length, the matrix is 01 matrix, and meet the elements up and down symmetry, left and right symmetry, asked to construct the number of 1 is the smallest matrix of x side length is how much.
Topic Analysis:
- First we can see that if the maximum number of n-1 constructs is greater than the maximum number constructed by N (n is even).
- And then we know that for each odd number, the maximum numbers that can be constructed are < Span class= "Mi" id= "mathjax-span-987" style= "font-size:70.7%; Font-family:mathjax_math-italic; " >n 2 + 1 2
- Then for each square matrix, in the horizontal axis and the longitudinal axis of the point are 221 groups, the same with the same, two axes of the intersection of their own group, then we found that if the maximum number of less than the current matrix x, it will be able to remove 4 a group of x%4, Since each matrix has a minimum of 1 groups of one group and a group of 2 groups (3 of cases are special), so there is 1,2,0, then can be early out of the x%4 of all numbers, so long as the current matrix of the maximum number greater than x can be constructed x.
AC Code:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace STD;intXintpos[]={1,5, -, -, A, A, -,113};intnum[]={1,3,5,7,9, One, -, the};intMain () { while( ~scanf("%d", &x)) {inti =0;if(x = =3) {puts("5");Continue; } while(Pos[i] < x) i++;printf("%d\n", Num[i]); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces 201A A. Clear symmetry (number theory + construction)