Clear Symmetry CodeForces - 201A

本文探讨了如何寻找最小正整数n,使得存在清晰且对称的n阶矩阵,其元素之和为给定整数x。清晰矩阵是指不包含相邻的1元素,而对称矩阵则指矩阵与其水平或垂直翻转后的形态相同。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

Example

Input
4
Output
3
Input
9
Output
5

Note

The figure below shows the matrices that correspond to the samples

题解:①当n是偶数时,n-1所用到1的个数比n多。

   ②当n是奇数时,最多能用(n*n+1)/2个1。

   ③能用奇数构成所有的x。

①和③没证明出来,画图归纳的。。。。。

注意:x=1,n=1; x=2,n=3; x=3,n=5;

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int x;
 5 int a[]={1,5,13,25,41,61,85,113};
 6 int b[]={1,3,5,7,9,11,13,15};
 7 
 8 int main()
 9 {   cin>>x;
10     int p=0;
11     if(x==3){ cout<<"5"<<endl; return 0; }
12     while(a[p]<x) p++;
13     cout<<b[p]<<endl;
14 } 

 

 

转载于:https://www.cnblogs.com/zgglj-com/p/7847049.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值