305850: CF1099B. Squares and Segments

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Squares and Segments

题意翻译

小索菲亚在四年级。今天,在几何课上,她学到了有关线段和正方形的知识。在回家的路上,她决定在雪中画n个边长为1的正方形。为了简单起见,我们假设Sofia生活在一个平面上,并且只能绘制与坐标轴平行、顶点位于整数点的长度为1的线段。 为了绘制一个段,Sofia进行如下操作。如果她想画一个端点为(x,y)和(x,y+1)垂直段。Sofia会查看是否已经有一个绘制的段,其端点为(x',y)和(x',y+1)。如果存在这样的段,那么Sofia将使用旧段作为指导,快速绘制新段。如果没有这样的线段,那么索菲亚就必须用尺子长时间测量一个新的线段。当索菲亚想画一个水平段时,也会发生同样的事情,但现在她才检查是否存在具有相同x,x+1坐标和不同y坐标的段。 例如,如果索菲亚需要画一个1 * 1的正方形,她必须用尺子画两段。 如果索菲亚需要画两个正方形,她必须用尺子画三段。 之后,她可以使用前三个部分作为向导绘制其余四个线段。 索菲亚很着急,所以她想尽量减少用尺子在没有向导的情况下绘制的线段数量。帮她找到这个最小数量。 # 输入格式 小正方形的数量n # 输出格式 一行,一个整数,表示最小数量

题目描述

Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw $ n $ squares in the snow with a side length of $ 1 $ . For simplicity, we assume that Sofia lives on a plane and can draw only segments of length $ 1 $ , parallel to the coordinate axes, with vertices at integer points. In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends $ (x, y) $ and $ (x, y+1) $ . Then Sofia looks if there is already a drawn segment with the coordinates of the ends $ (x', y) $ and $ (x', y+1) $ for some $ x' $ . If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates $ x $ , $ x+1 $ and the differing coordinate $ y $ . For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1099B/f22129ae6574d3dde7a981b244ceaeeeb94c0274.png)After that, she can draw the remaining two segments, using the first two as a guide: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1099B/97ef79b7e90b08453b2f04de3d242513bcb79574.png)If Sofia needs to draw two squares, she will have to draw three segments using a ruler: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1099B/193e3fcbc4091a8b6cb3aa67ae9bf3782b2e9ee1.png)After that, she can draw the remaining four segments, using the first three as a guide: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1099B/c9c6f752f1413cb3b2cb7f9d9bfc51906386e984.png)Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.

输入输出格式

输入格式


The only line of input contains a single integer $ n $ ( $ 1 \le n \le 10^{9} $ ), the number of squares that Sofia wants to draw.

输出格式


Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw $ n $ squares in the manner described above.

输入输出样例

输入样例 #1

1

输出样例 #1

2

输入样例 #2

2

输出样例 #2

3

输入样例 #3

4

输出样例 #3

4

Input

题意翻译

小索菲亚在四年级。今天,在几何课上,她学到了有关线段和正方形的知识。在回家的路上,她决定在雪中画n个边长为1的正方形。为了简单起见,我们假设Sofia生活在一个平面上,并且只能绘制与坐标轴平行、顶点位于整数点的长度为1的线段。 为了绘制一个段,Sofia进行如下操作。如果她想画一个端点为(x,y)和(x,y+1)垂直段。Sofia会查看是否已经有一个绘制的段,其端点为(x',y)和(x',y+1)。如果存在这样的段,那么Sofia将使用旧段作为指导,快速绘制新段。如果没有这样的线段,那么索菲亚就必须用尺子长时间测量一个新的线段。当索菲亚想画一个水平段时,也会发生同样的事情,但现在她才检查是否存在具有相同x,x+1坐标和不同y坐标的段。 例如,如果索菲亚需要画一个1 * 1的正方形,她必须用尺子画两段。 如果索菲亚需要画两个正方形,她必须用尺子画三段。 之后,她可以使用前三个部分作为向导绘制其余四个线段。 索菲亚很着急,所以她想尽量减少用尺子在没有向导的情况下绘制的线段数量。帮她找到这个最小数量。 # 输入格式 小正方形的数量n # 输出格式 一行,一个整数,表示最小数量

加入题单

上一题 下一题 算法标签: