CF1099B.Squares and Segments

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn squares in the snow with a side length of 11. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 11, 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)(x, y) and (x,y+1)(x, y+1). Then Sofia looks if there is already a drawn segment with the coordinates of the ends (x′,y)(x', y) and (x′,y+1)(x', y+1) for some x′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 xx, x+1x+1 and the differing coordinate yy.

For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler:

After that, she can draw the remaining two segments, using the first two as a guide:

If Sofia needs to draw two squares, she will have to draw three segments using a ruler:

After that, she can draw the remaining four segments, using the first three as a guide:

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.

小索菲亚上小学四年级。今天在几何课上,她学习了线段和正方形的概念。放学回家的路上,她决定在雪地上画 nn 个边长为 11 的正方形。为简化问题,我们假设索菲亚生活在一个平面上,且只能画出长度为 11、平行于坐标轴的线段,且所有端点均为整数坐标点。

索菲亚画一条线段的过程如下:若她想画一条竖直线段,其两个端点坐标为 (x,y)(x, y) 和 (x,y+1)(x, y+1),则她会先检查是否已存在某条竖直线段,其两个端点坐标为 (x′,y)(x', y) 和 (x′,y+1)(x', y+1)(其中 x′x' 为某个整数)。若存在这样的线段,则索菲亚可快速画出新线段,并以该已有线段为参照;否则,她必须借助直尺仔细测量,耗时较长。类似地,当她想画一条水平线段(端点为 (x,y)(x, y) 和 (x+1,y)(x+1, y))时,她会检查是否存在另一条水平线段,其两个端点具有相同的 xx、x+1x+1 坐标,而 yy 坐标不同(即是否已存在某条水平线段 (x,y′)(x, y') 和 (x+1,y′)(x+1, y'))。

例如,若索菲亚需画一个正方形,则她必须用直尺画出两条线段:

之后,她便可利用这两条已画好的线段作为参照,画出剩余的两条线段:

若索菲亚需画两个正方形,则她必须用直尺画出三条线段:

之后,她便可利用这三条已画好的线段作为参照,画出剩余的四条线段:

索菲亚赶时间,因此希望最小化必须用直尺(无参照)绘制的线段数量。请帮她找出这个最小数量。

输入格式

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

输入仅包含一行,其中有一个整数 nn(1≤n≤1091 \le n \le 10^{9}),表示索菲亚想要绘制的正方形数量。

输出格式

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

输出一个整数,即索菲亚按照上述方式画出 nn 个正方形时,必须用直尺(无辅助线)绘制的最少线段数量。

输入输出样例

  • 输入#1

    1

    输出#1

    2
  • 输入#2

    2

    输出#2

    3
  • 输入#3

    4

    输出#3

    4

输入解题思路,AI测评打分。不知道怎么写?

首页