codeforces 859B
来源:互联网 发布:大型网络3d手游2016年人气 编辑:程序博客网 时间:2024/06/08 13:32
Lazy Security Guard
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.
Example
Input
4
Output
8
Input
11
Output
14
Input
22
Output
20
Note
Here are some possible shapes for the examples:
题意:给出正方形的个数,拼到一起能够拼出最少的边;
思路:找规律,打表。
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespace std;long long a[1100000];int main(){ int n; a[0]=0; a[1]=4; a[2]=6; long long t=8; long long q=2; int i=3; while(1) { for(int j=0; j<q; j++) { a[i++]=t; } if(i>1000010) break; t+=2; for(int j=0; j<q; j++) { a[i++]=t; } q++; t+=2; if(i>1000010) break; }// for(int i=1;i<=25;i++)// cout<<a[i]<<endl; while(~scanf("%d",&n)) { cout<<a[n]<<endl; }}
阅读全文
0 0
- codeforces 859B
- codeforces 859B B. Lazy Security Guard
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- Codeforces 859B Lazy Security Guard
- Codeforces 859B Lazy Security Guard
- CodeForces 626B CodeForces 626B【暴力】
- CodeForces 841B (B) 博弈
- codeforces 134B
- codeforces#98 b
- codeforces 105 div2 B
- Codeforces 166B - Polygons
- codeforces B. Coins
- codeforces----193B Xor
- codeforces----208B Solitaire
- Codeforces 1B - Spreadsheet
- easydss的一种简单的实现hls流量统计的方法
- Vuejs介绍(一)
- 用jquery的ajax方法实现三级联动
- 数组map方法的用法
- UVa437 两种做法(DAG上的动态规划)
- codeforces 859B
- java 浅拷贝和深拷贝
- Oc GDataXML(DOM)解析表格
- 进程间通信方式(三)消息队列
- java.util.concurrent.TimeoutException: android.view.ThreadedRenderer.finalize() timed out after 10 s
- Oc GDataXML(DOM)解析分区表格
- ARM9 S3C2451 UART 理解
- Oc NSXMLParse(SAX)解析表格
- 编译caffe和matlab接口问题