Codeforces Round #127 (Div. 1) A. Clear Symmetry 打表

A. Clear Symmetry

题目连接:

http://codeforces.com/contest/201/problem/A

Description

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 n columns 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.

Sample Input

4

Sample Output

3

Hint

题意

给你一个x,你需要找到一个最小的正方形,使得这个正方形里面有x个1

这个正方形,需要满足1的方格不能相邻,且a[i][j]=a[n-i][j],a[i][j]=a[i][n-j],即上下对称,左右对称

然后问你边长最小是多少

题解:

数学题 打表

偶数是不考虑的,大概可以画画,很难满足对称性,且中间四个格子是浪费的

然后只用考虑奇数的情况

打表之后发现,奇数我们发现奇数长度的正方形能够容纳的1的个数满足公式2x(x+1)+1;

然后套进去就好了

代码

#include<bits/stdc++.h>
using namespace std;

int f(int x)
{
    x--;
    return 2*x*(x+1)+1;
}
int main()
{
    int n;
    scanf("%d",&n);
    if(n==3)return puts("5");
    int ans = 1;
    while(f(ans)<n)
        ans++;
    cout<<ans*2-1<<endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值