Codeforces 1099 B. Squares and Segments-思维(Codeforces Round #530 (Div. 2))
1 second
256 megabytes
standard input
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.
The only line of input contains a single integer nn (1≤n≤1091≤n≤109), 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 nn squares in the manner described above.
1
2
2
3
4
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))的更多相关文章
- Codeforces Round #530 (Div. 2) A,B,C,D
A. Snowball 链接:http://codeforces.com/contest/1099/problem/A 思路:模拟 代码: #include<bits/stdc++.h> ...
- Codeforces Round #530 (Div. 2) Solution
A. Snowball 签. #include <bits/stdc++.h> using namespace std; ], d[]; int main() { while (scanf ...
- Codeforces Round #530 (Div. 2) (前三题题解)
总评 今天是个上分的好日子,可惜12:30修仙场并没有打... A. Snowball(小模拟) 我上来还以为直接能O(1)算出来没想到还能小于等于0的时候变成0,那么只能小模拟了.从最高的地方进行高 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #530 (Div. 2) F (树形dp+线段树)
F. Cookies 链接:http://codeforces.com/contest/1099/problem/F 题意: 给你一棵树,树上有n个节点,每个节点上有ai块饼干,在这个节点上的每块饼干 ...
- 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号结 ...
- Codeforces Round #530 (Div. 2) F 线段树 + 树形dp(自下往上)
https://codeforces.com/contest/1099/problem/F 题意 一颗n个节点的树上,每个点都有\(x[i]\)个饼干,然后在i节点上吃一个饼干的时间是\(t[i]\) ...
随机推荐
- devDependencies 和 dependencise 的区别
在使用 npm install 安装模块或者插件的时候,在命令中可以添加俩种参数把他们写入到 pakeage.json 文件里面去: --save ( 简写 -S ) --save-dev ( 简写 ...
- Enterprise Architect 13 : 将绘制的图形导出成图片 或者 拷贝到剪贴板中
使用Enterprise Architect 13 工具画类图.包图.需求图.状态图.时序图什么的导出成图片格式 或者拷贝到剪贴版,步骤如下: Publish -> Save Image -&g ...
- java enum用法
基本用法 enum Day { SUNDAY, MONDAY, TUESDAY, WENDSDAY, THURSDAY, FRIDAY, SATURDAY; } 枚举是常量,所以应该用大写. 枚举是对 ...
- 【Codeforces629C】Famil Door and Brackets [DP]
Famil Door and Brackets Time Limit: 20 Sec Memory Limit: 512 MB Description Input Output Sample Inp ...
- 【BZOJ4819】【SDOI2017】新生舞会 [费用流][分数规划]
新生舞会 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 学校组织了一次新生舞会,Cathy ...
- bzoj 1705: [Usaco2007 Nov]Telephone Wire 架设电话线——dp
Description 最近,Farmer John的奶牛们越来越不满于牛棚里一塌糊涂的电话服务 于是,她们要求FJ把那些老旧的电话线换成性能更好的新电话线. 新的电话线架设在已有的N(2 <= ...
- cocos2dx中启用lua脚本
AppDelegate 的 applicationDidFinishLaunching 方法中加载Lua引擎 bool AppDelegate::applicationDidFinishLaunchi ...
- Spring 事务管理(山东数漫江湖)
最新又重新学习了一遍Spring的事务,这里做点总结,不做如何一步步配置的流水账. 1. 关键类 public interface PlatformTransactionManager { Trans ...
- Chinese Rings (九连环+矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目: Problem Description Dumbear likes to play th ...
- 详解JS中Number()、parseInt()和parseFloat()的区别
三者的作用: Number(): 可以用于任何数据类型转换成数值: parseInt().parseFloat(): 专门用于把字符串转换成数值: 一.Number( ): (1)如果是Boolean ...