hdu 5224 Tom and paper 水题
Tom and paper
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.uestc.edu.cn/#/contest/show/61
Description
Input
T≤10,n≤109
Output
对于每组数据输出一行一个整数,表示答案。
Sample Input
2
7
12
Sample Output
6
16
14
HINT
题意
题解:
枚举这张纸可能的长宽。因为面积为n的矩形必定存在一条边的边长不超过n√,所以只需枚举较短的边长,判断较长的边长是否是整数就可以了。
因为面积确定的矩形,长宽差越小,周长越小,所以可以从n√开始递减地枚举较短的边长,第一个合法的矩形就是答案。
时间复杂度:O(n√)
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int main()
{
int n;
int t=read();
while(t--)
{
n=read();
int ans=;
for(int i=sqrt(n+);i>=;i--)
{
if(i*(n/i)==n)
{
ans=(*i+*(n/i));
break;
}
}
cout<<ans<<endl;
}
return ;
}
hdu 5224 Tom and paper 水题的更多相关文章
- HDU 5224 Tom and paper(最小周长)
HDU 5224 Tom and paper(最小周长) Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d &a ...
- hdu 5224 Tom and paper
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5224 Tom and paper Description There is a piece of pa ...
- HDU 5578 Friendship of Frog 水题
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- HDU 5590 ZYB's Biology 水题
ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...
- HDU 5538 L - House Building 水题
L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- hdu 1005:Number Sequence(水题)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1018:Big Number(水题)
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 2041:超级楼梯(水题,递归)
超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...
- HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)
Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...
随机推荐
- Python3 动态导入模块的两种方式
动态导入模块就是只知道str类型的模块名字符串,通过这个字符串导入模块 需要导入的模块: #!/usr/bin/env python # _*_ coding:utf-8 _*_ # Author:C ...
- 在新版linux上编译老版本的kernel出现kernel/timeconst.h] Error 255
在使用ubuntu16.4编译Linux-2.6.31内核时出现这样的错误 可以修改timeconst.pl的内容后正常编译. 以下是编译错误提示的内容: Can't use 'defined(@ar ...
- Repository.UpdateModel(model, db);
Repository.UpdateModel(model, db); 可用类型 string int? datetime 不可用类型 int double
- [ python ] 各种推导式
各种推导式,主要使用示例演示用法 列表生成式 示例1:求0-9每个数的平方 li = [x*x for x in range(10)] print(li) # 执行结果: # [0, 1, 4, 9, ...
- 美化的select下拉框
ie7浏览器以后的下拉框,给他加上边框样式,是没用的.要是想做出样式好看的下拉框需要用js或者jquery来模拟实现. 代码如下: <div class="r"> &l ...
- Spring mvc知识点总结——面试篇
一.MVC思想MVC(Model-View-Controller)三元组的概念:1.Model(模型):数据模型,提供要展示的数据,因此包含数据和行为,可以认为是领域模型或JavaBean组件(包含数 ...
- cocos2dx 开发配置的一些环境变量(mac/linux)
通常开发需要配置一些环境变量,下面把我电脑的部分配置分析一下. 1.android开发配置,ndk,sdk,ant 2.cocos2dx开发配置,cocos2d-x export COCOS2DX_R ...
- 使用亚马逊云服务器EC2做深度学习(二)配置Jupyter Notebook服务器
这是<使用亚马逊云服务器EC2做深度学习>系列的第二篇文章. (一)申请竞价实例 (二)配置Jupyter Notebook服务器 (三)配置TensorFlow (四)配置好的系统 ...
- vue插件集合
Vue2.0+组件库总结 UI组件 element - 饿了么出品的Vue2的web UI工具套件 Vux - 基于Vue和WeUI的组件库 mint-ui - Vue 2的移动UI元素 iview ...
- LoadRunner中InvokeMethod failure: 外部组件发生异常解决办法
-82801 abnormal termination,caused by mdrv process termination -29996 error:process mmdrv.exe was no ...