CF 127 div1 A

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 andn 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 test(s)
input
4
output
3
input
9
output
5
Note

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

其实yy题真不知道怎么写解题报告,简单的画一下side从1到7的,注意题目要求一定是上下左右都对称。然后发现side是偶数时没有意义,再发现计数时可以包含1的最多个数的公式是(i/2)*i + (i/2+1)。最后特别注意一个trick,n=3时,答案是5.
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <string>
using namespace std;
typedef long long LL;
const int maxn = 100 + 5;


int f[maxn];

int main(){
    f[1] = f[2] = 1;
    for(int i = 3;i < maxn;i+=2){
        f[i] = f[i+1] = (i/2)*i + (i/2+1);
    }
    int n;
    while(cin >> n){
        if(n == 3){
            cout << 5 << endl;
            continue;
        }
        for(int i = 1;i < maxn;i+=2){
            if(n <= f[i]){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值