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. 【Python学习】使用Pyinstaller将py文件导出为exe文件

    PyInstaller其实就是把python解析器和你自己的脚本打包成一个可执行的文件,但是它不是跨编译的,也就是说在Windows下用PyInstaller生成的exe只能运行在Windows下,在 ...

  2. 【bzoj4486】【JSOI2015】串分割

    老省选题了. 首先考虑怎么比较超长数字的大小? 参见UTR1的那道题 先比size,然后比较字典序即可. 接下来考虑下切割的问题. 因为要将字符串切割成k份,所以这个字符串只会存在n/k个本质不同的起 ...

  3. iOS APP程序启动原理

    UIApplication 程序启动原理 一个应用程序运行就必须要有一个进程,一个进程至少要有一个线程,我们把这个线程叫做主线程,主线程开启之后会开启一个主运行循环,如果不开启一个运行循环,程序开启了 ...

  4. dockerfile实例--安装nginx

    [root@localhost ~]# vi Dockerfile //ADD FROM centos_with_net MAINTAINER frankie onez0714@.com RUN yu ...

  5. python笔记_查看函数调用栈的一个小技巧

    一.背景 最近在看一个开源框架的源码,涉及到的内容非常杂乱,有的函数不知道是在什么时候被谁给调用了?调用的时候传入了什么参数?为了解决这个问题,写了一个小的装饰器. 二.实现 这个装饰器函数主要参考了 ...

  6. git配置服务器版仓库

    1.git 可以使用四种主要的协议来传输数据:本地传输,SSH 协议,Git 协议和 HTTP 协议.现在使用360同步盘同步一个网络的仓库管理. 2.查看设置好的360同步盘的文件 3.创建空的仓库 ...

  7. 从设计图到CSS:rem+viewport+媒体查询+Sass

    根据UI图对移动端的h5页面做样式重构,是前端工程师的本职工作,看似简单,不过想做好却并不容易.下面总结一下其中要点. rem rem是一种相对长度单位,参考的基准是<html>标签定义的 ...

  8. leetcode 之Rotate Image(8)

    这题需要搞清楚矩阵元素的位置关系,尤其是副对角线元素,沿着副对角线元素 void rotateImage(vector<vector<int>> &matrix) { ...

  9. leetcode 之Implement strStr()(27)

    字符串的匹配,返回匹配开始的位置,直接用暴力方式求解.为了更快的匹配,定义一个指针表示待匹配的字符串的长度,当长度不足时,可 直接停止匹配. char *strStr(char *haystack, ...

  10. C语言 ,两个字符串参数,判断是否包含另一个字符串,返回所在位置

    char * cyp(char *s1,char *s2) { char *p = NULL; char *q = NULL; char *q1 = NULL; while(*s1!='\0') { ...