几何图形找规律——CaoHaha's staff

**题目:**Problem - 6154
http://acm.hdu.edu.cn/showproblem.php?pid=6154

Problem Description

“You shall not pass!”
After shouted out that,the Force Staff appered in CaoHaha’s hand.
As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.
But now,his new owner,CaoHaha,is a sorcerers apprentice.He can only use that staff to send things to other place.
Today,Dreamwyy come to CaoHaha.Requesting him send a toy to his new girl friend.It was so far that Dreamwyy can only resort to CaoHaha.
The first step to send something is draw a Magic array on a Magic place.The magic place looks like a coordinate system,and each time you can draw a segments either on cell sides or on cell diagonals.In additional,you need 1 minutes to draw a segments.
If you want to send something ,you need to draw a Magic array which is not smaller than the that.You can make it any deformation,so what really matters is the size of the object.
CaoHaha want to help dreamwyy but his time is valuable(to learn to be just like you),so he want to draw least segments.However,because of his bad math,he needs your help.

Input

The first line contains one integer T(T<=300).The number of toys.
Then T lines each contains one intetger S.The size of the toy(N<=1e9).

Output

Out put T integer in each line ,the least time CaoHaha can send the toy.

Sample Input

5
1
2
3
4
5

Sample Output

4
4
6
6
7

Source

2017中国大学生程序设计竞赛 - 网络选拔赛
题意:题意:给出T组数据,每组包含一个正整数S表示最小面积,现在要求在一个矩阵中,每一笔只能画一条边或一条对角线,求出最少需要多少笔能画出面积大于等于S的区域 。就是说一笔是对角线,那么长度是根号2.如果是边,那么就是1.
分析
我们只需要找到,化n笔,最大可以化出多大的面积,这样找到大于或者等于给出物体尺寸的最小值。就行了。由于要围成封闭图形,最少要3条边,但是这样面积最大才0.5。所有不行,因为比最小的物体尺寸还小。那么就4条边,发现。以对角线作为边围成棱形时最大。接着,后面试着加一笔,然后加2笔等等,就发现,要批成一个菱形。要加上4条才行,所以4是一个周期。具体的,自己动手画吧。
看看这个解释,里面有图,很详细。http://blog.csdn.net/qq_38576126
代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    int t;
    int n;
    double sum=0;
    int b;
    scanf("%d",&t);
    while(t--){
        b=4;
        scanf("%d",&n);
        sum=2;
        while(n){
            if(sum>=n)
            break;
            b++; 
            if(b%4==1)
            sum=sum+0.5+b/4-1;
            else if(b%4==2||b%4==3)
            sum=sum+1.5+b/4-1;
            else sum=sum+2.5+b/4-2;//注意这里是减2,因为b/4等于1了。 

        }
        printf("%d\n",b);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值