hdoj 6154 CaoHaha's staff
来源:互联网 发布:淘宝信誉多少一个皇冠 编辑:程序博客网 时间:2024/06/01 08:37
题目链接:CaoHaha’s staff
题目大意:给你一个面积,要求你用最少的边构成一个多边形,这个多边形的面积大于等于这个面积
题目思路:要使面积尽量的大我们要有尽量多的斜边,那么我们可以从斜边正方形的基础上来加边看面积的变化,如当有4条边时,能围成的最大面积为这样的斜边正方形,然后考虑加一条边时的情况黑色斜边变为红边,黄边为增加的边,那么面积就在原来的基础上增加了0.5然后考虑再增加一条边,我们进行同样的操作面积增加0.5,但是这并不是最大的面积,我们进行这样的操作把增加的两条直边变为斜边,这样使得面积增加了0.5+1,最后我们增加了4条边后重复操作图形就会变成
(以上图片与思路,均来自此博客)http://blog.csdn.net/ftx456789/article/details/77414955
然后我们就可以把n条边能存的最大面积找到了,然后模拟一下存数组,然后二分去找就好了
#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <vector>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;double a[100010];void solve(){ a[4] = 2; for(int i = 4;i <= 100010;i += 4){ double ans = i/4-0.5; a[i+1] = a[i]+ans; a[i+2] = a[i+1]+ans+1; a[i+3] = a[i+2]+ans+1; a[i+4] = a[i+3]+ans+2; }}int main(){ int n,t; solve(); scanf("%d",&t); while(t--){ scanf("%d",&n); printf("%d\n",lower_bound(a,a+100010,n)-a); } return 0;}
阅读全文
0 0
- hdoj 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- Hdu 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- hdu 6154 CaoHaha's staff
- hdu 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff 找规律
- HDU 6154-CaoHaha's staff(ccpc)
- HDU 6154 CaoHaha's staff(规律)
- Hdu 6154 CaoHaha's staff【思维】
- HDU 6154 CaoHaha's staff【找规律】
- HDU 6154 CaoHaha's staff 找规律
- HDU 6154 CaoHaha's staff (数学)
- hdu 6154 CaoHaha's staff【找规律】
- 我对C++的前景看法 C++和C#的对比
- 获取数据库连接失败解决方案
- C++类和对象知识点整理二
- 字符串反转--句子反转和单词反转
- Column count doesn't match value count at row 1 问题Column count doesn't match value count at row 1
- hdoj 6154 CaoHaha's staff
- Mac 开启任何来源选项
- zoj 3416 Balanced Number 数位dp
- 为什么 objc_msgSend 必须用汇编实现
- hive2.1安装
- string.reserve 与 string.resize的区别
- PHP 二维数组去掉重复值并保持原结构
- Java之Enum类中的ordinal函数-yellowcong
- Linux中设置服务自启动的三种方式