hdu 6154 CaoHaha's staff【找规律】
来源:互联网 发布:电脑广告制作软件 编辑:程序博客网 时间:2024/05/18 02:03
题目
http://acm.hdu.edu.cn/showproblem.php?pid=6154
题意
在笛卡尔坐标系下,画一个面积至少为 nn 的简单多边形,每次只能画一条边或者一个格子的对角线,问至少要画几条。
分析
至少 4 条边才能围成封闭图形,然后考虑对于每一条边,最多能围成的面积。如果是偶数条边,那么就是使得两条边长度差最小得到的面积。如果是奇数条边,那么就是,首先少用一条,然后围成一个偶数条边的最大矩形,之后在这个矩形的较长边上增加一条边,可以突出一个梯形的部分,这就是对应的最大面积。
代码
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <string>#include <vector>#include <queue>#include <map>#include <set>#include <cmath>using namespace std;int Area(int x){ if(x%4==0)return x/4*(x/4)*2; else if(x%2==0) return x/4*(x/4+1)*2; else return Area(x-1)+(x-2)/4;}int main(){ int T;scanf("%d",&T); while(T--){ int n; scanf("%d",&n); for(int i=4;;i++){ if(Area(i)>=n){ printf("%d\n",i ); break; } } } return 0;}
阅读全文
0 0
- 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(规律)
- HDU6154 CaoHaha's staff 找规律|签到
- hdu6154-CaoHaha's staff(找规律)
- hdu6154 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
- bzoj 4094: [Usaco2013 Dec]Optimal Milking 线段树
- 卓美业带来美业管理全新体验,内测中
- matlab中函数与opencv中对应
- HDU 6156 Palindrome Function (数位dp)
- rgb-d slam(2)笔记
- hdu 6154 CaoHaha's staff【找规律】
- 集合框架(五) java中的泛型
- 日常问题
- Java 枚举7常见种用法
- UVA 10881Piotr's Ants
- c语言中的rand()函数和srand()函数产生随机的整数
- 关于*P双机调试的学习
- OpenCV探索之路(二十四)图像拼接和图像融合技术
- LeetCode average Of Levels in Binary Tree