CF 201 A. Clear Symmetry(数学+模拟)

版权声明:这些都是咸鱼Nova最后的挣扎,各位大佬转载请注明出处 https://blog.csdn.net/weixin_40883049/article/details/79108789

A. Clear Symmetry

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and ncolumns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the i-row and the j-th column as Ai, j.

Let's call matrix A clear if no two cells containing ones have a common side.

Let's call matrix A symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (i, j) (1 ≤ i, j ≤ n) both of the following conditions must be met: Ai, j = An - i + 1, j and Ai, j = Ai, n - j + 1.

Let's define the sharpness of matrix A as the number of ones in it.

Given integer x, your task is to find the smallest positive integer n such that there exists a clear symmetrical matrix A with side n and sharpness x.

Input

The only line contains a single integer x (1 ≤ x ≤ 100) — the required sharpness of the matrix.

Output

Print a single number — the sought value of n.

Examples

input

4

output

3

input

9

output

5

Note

The figure below shows the matrices that correspond to the samples:

题意:给你一个数n,表示有n个1,现在你要创造一个n*n的矩阵,把这n个1填到矩阵里,且每两个1之间不能相邻,且构成的矩阵关于横方向和纵方向对称,问所需矩阵最短边长为多少。

心路历程:刚开始找规律被n=3时坑了,3需要特判。

首先由国际棋盘知每个矩阵最多能容下的1的摆法为隔一个摆一个,所以对于奇数矩阵,最多可以摆下(i^2+1)/2, 对于偶数矩阵

最多可以摆下i^2/2,且从试验的结果知,偶数边矩阵无法同时满足对称,不相邻,最少,这三个条件,所以只用讨论奇数边

除了3之外,任何的数都可以由摆下临界值的矩阵摆下。例如,3*3最多摆下5个,5*5可以摆下13个,则5—13的数都可由5*5摆下

ac代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int x;
    int sum[50];
    for(int i=1; i<=50; i+=2) sum[i]=(i*i+1)/2;//先把每个盘所能摆下的1存下来
    while(~scanf("%d",&x))
    {
        if(x==3)//特判3
        {
            printf("5\n");
            continue;
        }
        for(int i=1; i<=50; i+=2)
        {
            if(sum[i]>=x)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_40883049/article/details/79108789
201