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. FindQQByProcess

    看网上有许多通过进程寻找QQ号的例子,看了一下,里面涉及的知识点还是比较多,但网上的兼容性不太好,而且没有给出匹配字符的来源,所以自己动手写了一下,顺便给出一些我调试的结果. #include &qu ...

  2. inetdev_init && inetdev_destroy

    inetdev_init为传入设备分配和绑定ip控制块,查看其调用关系如下: fs_initcall(inet_init)---->inet_init---->ip_init----> ...

  3. monkey测试===如何获取android app的Activity

    方法一(推荐): 手机连接adb,手机界面在需要取得activity的界面. 推荐使用该命令: adb shell dumpsys activity top | findstr ACTIVITY 获取 ...

  4. 64_c1

    CBFlib-0.9.5.15-3.fc26.i686.rpm 05-Feb-2017 21:55 427710 CBFlib-0.9.5.15-3.fc26.x86_64.rpm 05-Feb-20 ...

  5. 2017多校第10场 HDU 6172 Array Challenge 猜公式,矩阵幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6172 题意:如题. 解法: #include <bits/stdc++.h> using ...

  6. 获取windows 网卡GUID和ip信息

    # coding: UTF-8 import _winreg GUID=dict() num = 0 netCfgInstanceID = None hkey = _winreg.OpenKey(_w ...

  7. C#判断目录是否为隐藏

    判断方法: DirectoryInfo di = new DirectoryInfo(path); if ((di.Attributes & FileAttributes.Hidden) == ...

  8. PHP设计模式二-------单例模式

    1.单例模式的介绍 意图:保证一个类仅有一个实例,并提供一个访问它的全局访问点: 主要解决:一个全局使用的类频繁地创建与销毁. 关键代码:构造函数是私有的,克隆方法也是私有的. 1.1 懒汉式//1 ...

  9. LockSupport学习

    LockSupport工具类定义了一组的公共静态方法,这些方法提供了最基本的线程阻塞和唤醒功能.Java锁和同步器框架的核心工具类AQS:AbstractQueueSynchronizer,就是通过调 ...

  10. Python+Selenium 自动化实现实例-Xpath捕捉元素的几种方法

    #coding=utf-8import timefrom selenium import webdriverdriver = webdriver.Chrome()driver.get("ht ...