zoukankan      html  css  js  c++  java
  • hdu 6154 CaoHaha's staff

    CaoHaha's staff

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 487    Accepted Submission(s): 286


    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
    Recommend
    liuyiding   |   We have carefully selected several similar problems for you:  6160 6159 6158 6157 6156 
     

    题意:

    一笔可以画一条长为1的边或者一条根号二的对角线,问围成一个面积是n 的图形最少需要几条边

    题解:

    找规律画图 

    这题可以先把问题转化为已知画m笔,最大可以画出多大的面积

    当m%4==0,画sqrt(2)的边,可以达成最大的面积

    当m%4==1,就把[m/4]*4围成的图像的 最长边往外推sqrt(2)/2,比原来增加一个梯形的面积

    当m%4==2,就把[m/4]*4围成的图像的 最长边往外推sqrt(2)长度,增加一个小矩形面积

    当m%4==3,在m%4==2的基础上实行m%4==1一样的操作

    #include <iostream>
    #include<bits/stdc++.h>
    using namespace std;
    
    int t;
    int n,sd;
    
    int sumS(int m)  //m是周长,推出公式就可以了
    {
        int d=m/4; 
        if (m%4==0) return 2*d*d;  
        if (m%4==1) return 2*d*d+d-1;
        if (m%4==2) return 2*d*d+2*d;
        if (m%4==3) return 2*d*d+3*d;
    }
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            sd=(int)sqrt(n/2.0)*4;  //最小的周长
            while(1)
            {
                if (sumS(sd)>=n) {printf("%d
    ",sd); break;}
                sd++;
            }
        }
      return 0;
    }
  • 相关阅读:
    如何编译Linux内核
    linux启动过程
    linux ifconfig
    Android 4.0 x86安装教程 附带联网参数详细设置
    linux ntfs模块
    Java 入门进阶
    深入理解Java中的String
    Java中字符串string的数据类型
    IDEA设置JVM运行参数
    Java11实战:模块化的 Netty RPC 服务项目
  • 原文地址:https://www.cnblogs.com/stepping/p/7401016.html
Copyright © 2011-2022 走看看