• Heron and His Triangle HDU


    ---恢复内容开始---

    Heron and His Triangle

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 2543    Accepted Submission(s): 1060


    Problem Description
    A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integers t−1, t, t+ 1 and thatits area is an integer. Now, for given n you need to find a Heron’s triangle associated with the smallest t bigger
    than or equal to n.
     
    Input
    The input contains multiple test cases. The first line of a multiple input is an integer T (1 ≤ T ≤ 30000) followedby T lines. Each line contains an integer N (1 ≤ N ≤ 10^30).
     
    Output
    For each test case, output the smallest t in a line. If the Heron’s triangle required does not exist, output -1.
     
    Sample Input
    4 1 2 3 4
     
    Sample Output
    4 4 4 4
     
    Source
     
    Recommend
    jiangzijing2015

    遇到求三角形面积且已知三边长 那就用海伦公式

    Heron and His Triangle

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 2543    Accepted Submission(s): 1060


    Problem Description
    A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integers t−1, t, t+ 1 and thatits area is an integer. Now, for given n you need to find a Heron’s triangle associated with the smallest t bigger
    than or equal to n.
     
    Input
    The input contains multiple test cases. The first line of a multiple input is an integer T (1 ≤ T ≤ 30000) followedby T lines. Each line contains an integer N (1 ≤ N ≤ 10^30).
     
    Output
    For each test case, output the smallest t in a line. If the Heron’s triangle required does not exist, output -1.
     
    Sample Input
    4 1 2 3 4
     
    Sample Output
    4 4 4 4
     
    Source
     
    Recommend
    jiangzijing2015

    首先根据题意设a=t-1,b=t,c=t+1,这样我们可由海伦凯勒公式得到

                               

    那么要想使得s为整数,就要使      等于3乘以一个平方数

    所以我们设            

    于是得到               d=3

    根据题意可知最小特解为x=2,y=1;

    打个表之后发现这样一些数字4,14,52,194,724,2702....然后得出递推式子,F[n]=4*F[n-1]-F[n-2];由于n非常的大,所以矩阵快幂维护也不行。最后考虑这样的数字几乎增长比较快,那么范围内这样的数字就会比较少,不想用高精度的可以考虑用java大数了,用个list将所有n范围内的结果保存一下,最后直接查询就可以了。

    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    ubuntu11.04解决root不能登录的问题
    应用C预处理命令
    WINCE6.0在控制面板添加控制面板应用程序
    嵌入式系统开发
    WINCE6.0下开始菜单的“挂起(suspend)”是否可见及阻止系统进入睡眠模式
    WINCE6.0更换桌面壁纸和图标
    ubuntun_11.04安装
    WINCE开发更安全可靠设备驱动的最佳实践
    WINCE源代码配置文件
    TS2003基于触摸屏的应用
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/10294413.html
Copyright © 2020-2023  润新知