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;
}

Codeforces Round #127 (Div. 1) A. Clear Symmetry 打表的更多相关文章

  1. Codeforces Round #127 (Div. 2)

    A. LLPS 长度最大10,暴力枚举即可. B. Brand New Easy Problem 枚举\(n\)的全排列,按题意求最小的\(x\),即逆序对个数. C. Clear Symmetry ...

  2. Codeforces Round #127 (Div. 1) E. Thoroughly Bureaucratic Organization 二分 数学

    E. Thoroughly Bureaucratic Organization 题目连接: http://www.codeforces.com/contest/201/problem/E Descri ...

  3. Codeforces Round #127 (Div. 1) D. Brand New Problem 暴力dp

    D. Brand New Problem 题目连接: http://www.codeforces.com/contest/201/problem/D Description A widely know ...

  4. Codeforces Round #127 (Div. 1) C. Fragile Bridges dp

    C. Fragile Bridges 题目连接: http://codeforces.com/contest/201/problem/C Description You are playing a v ...

  5. Codeforces Round #127 (Div. 1) B. Guess That Car! 扫描线

    B. Guess That Car! 题目连接: http://codeforces.com/contest/201/problem/B Description A widely known amon ...

  6. Codeforces Round #422 (Div. 2)E. Liar sa+st表+dp

    题意:给你两个串s,p,问你把s分开顺序不变,能不能用最多k段合成p. 题解:dp[i][j]表示s到了前i项,用了j段的最多能合成p的前缀是哪里,那么转移就是两种,\(dp[i+1][j]=dp[i ...

  7. Codeforces Round #278 (Div. 1) B - Strip dp+st表+单调队列

    B - Strip 思路:简单dp,用st表+单调队列维护一下. #include<bits/stdc++.h> #define LL long long #define fi first ...

  8. Codeforces Round #493 (Div. 1) B. Roman Digits 打表找规律

    题意: 我们在研究罗马数字.罗马数字只有4个字符,I,V,X,L分别代表1,5,10,100.一个罗马数字的值为该数字包含的字符代表数字的和,而与字符的顺序无关.例如XXXV=35,IXI=12. 现 ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. linux编程之信号量编程

    信号量当我们在多用户系统,多进程系统,或是两者混合的系统中使用线程操作编写程序时,我们经常会发现我们有段临界代码,在此处我们需要保证一个进程(或是一个线程的执行)需要排他的访问一个资源.信号量有一个复 ...

  2. Ubuntu 14.04 安装gstreamer0.10-ffmpeg

    sudo apt-add-repository ppa:mc3man/trusty-media sudo apt-get update sudo apt-get install -y gstreame ...

  3. STM32 volatile关键字

    为了提供对特殊地址的稳定访问. [C] 纯文本查看 复制代码 ? 1 2 3 int i=10; int j=i;     //1 int k=i;    //2 此时编译器对上面代码进行优化,因为在 ...

  4. 为什么要用Jedis连接池+浅谈jedis连接池使用

    为什么要使用Jedis连接池 Redis作为缓存数据库理论上和MySQL一样需要客户端和服务端建立起来连接进行相关操作,使用MySQL的时候相信大家都会使用一款开源的连接池,例如C3P0.因为直连会消 ...

  5. myeclipse安装插件phpeclipse后进行PHP代码编写

    平常一般写java代码,有时也捣腾一下php,原来安装过zend studio来编写php代码,无奈电脑越来越卡,于是卸载了zend,然后在myeclipse中安装phpeclipse这款插件来完成p ...

  6. input标签获取焦点时文本框内提示信息清空背景颜色发生变化

    <input type="text" id="username" onfocus="myFocus(this,'#f4eaf1')" ...

  7. IntelJ IDEA 进行Java Web开发+热部署+一些开发上的问题

    基本上像放弃MyEclipse或者Eclipse了,因为IDEA现在也有对应的版本旗舰版和社区版了,而且使用更贴心,更给力,为什么还要选一个难用的要死的东西呢? 最近要开发一个Java Web项目,所 ...

  8. inline-block,vertical-align:middle

    现在inline-block貌似可以替代float来实现多个item的排列分布吧 div是块级元素,如果不设置他的明确的宽度,那他就等于父元素的宽度,如果想让他其它随着子元素的变化而变化,需要改变他的 ...

  9. ES6新数据结构Set让数组去重

    function unique(array){ return Array.from(new Set(array)); } var arr = ['aa','bb','cc','',1,0,'1',1, ...

  10. node中--save跟--save--dev

    --save参数表示将该模块写入dependencies属性, --save-dev表示将该模块写入devDependencies属性.   dependencies字段指定了项目运行所依赖的模, d ...