Codeforces 201A A. Clear symmetry (number theory + construction)

Source: Internet
Author: User

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)

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.