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 ...
随机推荐
- BERT(Bidirectional Encoder Representations from Transformers)理解
BERT的新语言表示模型,它代表Transformer的双向编码器表示.与最近的其他语言表示模型不同,BERT旨在通过联合调节所有层中的上下文来预先训练深度双向表示.因此,预训练的BERT表示可以通过 ...
- Linux下帮助命令
帮助命令(各种命令区别) 最常用的帮助命令 help --help help cd 查看内置命令的使用 info man help cd 查看内置命令的使用 获得帮助的途径: ma ...
- 创建一个简单的Maven工程
Maven的工程结构如下图所示: 大致来看,Maven的工程结构如下: 在创建maven工程时,可以通过骨架创建,也可以不通过骨架创建. 我们先用idea通过骨架创建一个Maven工程. 配置pom. ...
- IDE按住ctrl 打开单元 无效时 的方法
一般打开单元无效时 是由于程序有错误,若程序没有错误 可以重新build一下 再试. 若实在不行 就右键---open at cursor
- 欧拉回路&欧拉通路判断
欧拉回路:图G,若存在一条路,经过G中每条边有且仅有一次,称这条路为欧拉路,如果存在一条回路经过G每条边有且仅有一次, 称这条回路为欧拉回路.具有欧拉回路的图成为欧拉图. 判断欧拉通路是否存在的方法 ...
- centos7 lvs+keepalived nat模式
1.架构图 3.地址规划 主机名 内网ip 外网ip lvs-master 192.168.137.111(仅主机)eth1 172.16.76.111(桥接)eth0 lvs-slave 192 ...
- Eolinker----全局变量的不同场景使用
因为目前eolinker的API自动化测试不支持“构造参数”,因此针对“全局变量”的使用在不同的场景下,可采用不同的方式实现,但是一个参数既然设计成为了全局变量,那么在接口中使用时尽量保证书写风格一致 ...
- markdown 测试代码
这是 H1 这是 H2 这是 H3 这是 H4 这是 H5 这是 H6 A First Level Header A Second Level Header Now is the time for a ...
- LoadRunner 中的 Unique Number 参数类型小结
- ubuntu sublime text 3 build 3083 license
经验证:sublime text 3 3083可用 ----- BEGIN LICENSE -----Andrew WeberSingle User LicenseEA7E-855605813A03D ...