【CF MEMSQL 3.0 B. Lazy Security Guard】
time limit per test 2 seconds
memory limit per test 256 megabytes
input standard input
output standard output
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly N city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly N blocks. Your friend is quite lazy and would like your help to find the shortest possible route that meets the requirements. The city is laid out in a square grid pattern, and is large enough that for the sake of the problem it can be considered infinite.
Input
Input will consist of a single integer N (1 ≤ N ≤ 106), the number of city blocks that must be enclosed by the route.
Output
Print the minimum perimeter that can be achieved.
Examples
input
4
output
8
input
11
output
14
input
22
output
20
Note
Here are some possible shapes for the examples:

【翻译】有n个长度为1的正方形块拼在一起,求最小周长。
题解:
①先对n开根的出近似边长x。
②尝试周长:x*x ,x*(x+1), (x+1)*(x+1),只要块数大于n,输出最小值就可以了。
#include<stdio.h>
#include<math.h>
using namespace std;
int n,a;
int main()
{
scanf("%d",&n);
a=floor(sqrt(1.0*n)+0.0001);
if(a*a>=n)printf("%d\n",4*a);
else if(a*(a+1)>=n)printf("%d\n",4*a+2);
else if((a+1)*(a+1)>=n)printf("%d\n",4*a+4);return 0;
}//Paul_Guderian
【CF MEMSQL 3.0 B. Lazy Security Guard】的更多相关文章
- 【CF MEMSQL 3.0 D. Third Month Insanity】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF MEMSQL 3.0 A. Declined Finalists】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF MEMSQL 3.0 E. Desk Disorder】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF MEMSQL 3.0 C. Pie Rules】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]
就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...
- 【MemSQL Start[c]UP 3.0 - Round 1 B】 Lazy Security Guard
[链接]h在这里写链接 [题意] 围成对应面积的方块最少需要多少条边. [题解] 有特定的公式的. 2*ceil(2*根号下(n)); -> 自己找下规律也很简单的. [错的次数] 0 [反思] ...
- 【CF edu 30 C. Strange Game On Matrix】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standa ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
随机推荐
- 使用MapReduce读取HBase数据存储到MySQL
Mapper读取HBase数据 package MapReduce; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hba ...
- python-生成器单线程并发(简单案例)
#!/usr/local/bin/python3 # -*- coding:utf-8 -*- import time # ----------示例---------- def consumer(na ...
- 《史上最简单的MySQL教程》系列分享专栏
<史上最简单的MySQL教程>系列分享专栏 <史上最简单的MySQL教程>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read ...
- es同步mysql同步-logstash
1.下载es https://www.elastic.co/downloads/elasticsearch 修改 config 下elasticsearch.yml ip和端口等配置 2.下载ki ...
- Can’t delete list item in Sharepoint2013
Today,I have meet a very strange error.When I attempt to delete a item from a list,I recieve an ...
- webpack实践总结
一.Loader写法及执行顺序 从webpack2起,loader的格式如下: module: { rules: [ {test: /\.css$/, use: ['style-loader','cs ...
- js复制粘贴事件
一.相应的事件 copy: 在发生复制操作时触发. beforecut: 在发生剪切操作 前 触发. cut: 在 发生 剪切 操作 时 触发. beforepaste: 在 发生 粘贴 操作 前 触 ...
- PHP管理供下载的APK文件
当我们开发的APP多的时候,把所有的APK文件统一放到一个目录中管理,是一个不错的选择: 管理的方法有很多,这里说一种: 1..创建目录结构,先创建根目录download,在根目录中创建项目目录,在项 ...
- 问题 C: 质因数的个数
1947: 质因数的个数 时间限制: 1 Sec 内存限制: 32 MB提交: 245 解决: 114[提交][状态][讨论版][命题人:外部导入] 题目描述 求正整数N(N>1)的质因数的 ...
- Ubuntu16.04 + CUDA9.0 + cuDNN7.3 + Tensorflow-gpu-1.12 + Jupyter Notebook 深度学习环境配置
目录 一.Ubuntu16.04 LTS系统的安装 二.设置软件源的国内镜像 1. 设置方法 2.关于ubuntu镜像的小知识 三.Nvidia显卡驱动的安装 1. 首先查看显卡型号和推荐的显卡驱动 ...