B. Squares and Segments

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The only line of input contains a single integer nn (1≤n≤1091≤n≤109), the number of squares that Sofia wants to draw.

Output

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.

Examples
input

Copy
1
output

Copy
2
input

Copy
2
output

Copy
3
input

Copy
4
output

Copy
4

题意就是找最接近当前数的一个数的两个因数,比如41,就是6*7,就是6+7的结果。如果按照41来算,那么需要41+1=42,如果是按照42来算,就是6+7,还有10,最接近的是3+4,是12的,就是这样的题目。

代码:

 //B
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll; const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=2e7+;
const int maxm=+;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int main()
{
int n;
cin>>n;
int p=sqrt(n);
int ans=inf,flag=;
if(n==){
ans=;
cout<<ans<<endl;
return ;
}
if(p*p==n)ans=min(*p,ans);
else if(p*(p+)>=n) ans=min(p+p+,ans);
else ans=min(*(p+),ans);
cout<<ans<<endl;
}

Codeforces 1099 B. Squares and Segments-思维(Codeforces Round #530 (Div. 2))的更多相关文章

  1. Codeforces Round #530 (Div. 2) A,B,C,D

    A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: #include<bits/stdc++.h> ...

  2. Codeforces Round #530 (Div. 2) Solution

    A. Snowball 签. #include <bits/stdc++.h> using namespace std; ], d[]; int main() { while (scanf ...

  3. Codeforces Round #530 (Div. 2) (前三题题解)

    总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高 ...

  4. Codeforces 1099 D. Sum in the tree-构造最小点权和有根树 贪心+DFS(Codeforces Round #530 (Div. 2))

    D. Sum in the tree time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces 1099 C. Postcard-字符串处理(Codeforces Round #530 (Div. 2))

    C. Postcard time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  6. Codeforces 1099 A. Snowball-暴力(Codeforces Round #530 (Div. 2))

    A. Snowball time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  7. Codeforces Round #530 (Div. 2) F (树形dp+线段树)

    F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...

  8. Codeforces Round #530 (Div. 2):D. Sum in the tree (题解)

    D. Sum in the tree 题目链接:https://codeforces.com/contest/1099/problem/D 题意: 给出一棵树,以及每个点的si,这里的si代表从i号结 ...

  9. Codeforces Round #530 (Div. 2) F 线段树 + 树形dp(自下往上)

    https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\) ...

随机推荐

  1. 解决oracle数据库 ora-00054:resource busy and acquire with NOWAIT specified 错误

    解决oracle数据库 ora-00054:resource busy and acquire with NOWAIT specified 错误 本人在使用pl/sql developer 客户端调用 ...

  2. Python爬虫学习笔记之微信宫格验证码的识别(存在问题)

    本节我们将介绍新浪微博宫格验证码的识别.微博宫格验证码是一种新型交互式验证码,每个宫格之间会有一条 指示连线,指示了应该的滑动轨迹.我们要按照滑动轨迹依次从起始宫格滑动到终止宫格,才可以完成验证,如 ...

  3. CSS实现三列布局方法总结

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABYwAAAI7CAYAAABPx9+YAAARJElEQVR4nO3cwWnDQBBA0TioJrXhTl

  4. LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合

    题意:10000组数据 问一个数n[1,1e12] 在k进制下有末尾0的k的个数. 思路:题意很明显,就是求n的因子个数,本来想直接预处理欧拉函数,然后拿它减n就行了.但注意是1e12次方法不可行.而 ...

  5. 【51NOD】消灭兔子

    [算法]贪心 #include<cstdio> #include<algorithm> #include<cstring> #include<queue> ...

  6. 【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

    [算法]贪心&&堆 [题解]反过来看就是合并任意两块木板,花费为木板长度之和. 显然从最小的两块开始合并即可,用堆(优先队列)维护. 经典DP问题石子归并是只能合并相邻两堆石子,所以不 ...

  7. 【CF558E】 A Simple Task (权值线段树)

    题目链接 用权值线段树维护每个字母在\([l,r]\)出现的次数,每次修改把每个字母在区间的出现次数记下来,然后清空这段区间,再按顺序插进去就好了. 时间复杂度\(O(n\log n*26)\) (好 ...

  8. python初步学习-python数据类型-集合(set)

    集合 在已经学过的数据类型中: 能够索引的,如list/str,其中的元素可以重复 可变的,如list/dict,即其中的元素/键值对可以原地修改 不可变的,如str/int,即不能进行原地修改 无索 ...

  9. bzoj 1188 SG函数

    首先我们可以把一个石子看成一个单独的游戏,那么我们可以发现所有位置的石子至于奇偶有关,因为某一个人操作其中的一个石子,我们可以用相同的石子做相同的操作,所以我们只需要保留下所有位置的01,那么对于每个 ...

  10. A题 hdu 1235 统计同成绩学生人数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1235 统计同成绩学生人数 Time Limit: 2000/1000 MS (Java/Others) ...