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

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范围内的结果保存一下,最后直接查询就可以了。

Heron and His Triangle HDU - 6222(pell 大数)的更多相关文章

  1. Heron and His Triangle HDU - 6222

    题目链接:https://vjudge.net/problem/HDU-6222 思路:打表找规律. 然后因为数据范围较大可以考虑用字符串模拟,或者__int128要注意用一个快读快输模板. 1 #i ...

  2. HDU 6222 Heron and His Triangle (pell 方程)

    题面(本人翻译) A triangle is a Heron's triangle if it satisfies that the side lengths of it are consecutiv ...

  3. Heron and His Triangle 2017 沈阳区域赛

    A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integer ...

  4. 2017 ACM/ICPC 沈阳 F题 Heron and his triangle

    A triangle is a Heron’s triangle if it satisfies that the side lengths of it are consecutive integer ...

  5. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...

  6. HDU 1715 (大数相加,斐波拉契数列)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1715 大菲波数 Time Limit: 1000/1000 MS (Java/Others)     ...

  7. hdu 5718(Oracle)大数加法

    曾经有一位国王,统治着一片未名之地.他膝下有三个女儿. 三个女儿中最年轻漂亮的当属Psyche.她的父亲不确定她未来的命运,于是他来到Delphi神庙求神谕. 神谕可以看作一个不含前导零的正整数n n ...

  8. hdu 5351 规律+大数

    题目大意:定义了一种fib字符串,问第n个fib串的前m个字母前后相等串的最大长度,大约就是这样的 其实主要读完题意的时候并没有思路,但是列几个fib字符串就会发现,除了fib1以外,所有串的前面都是 ...

  9. hdu 1063 Exponentiation 大数

    Problem Description Problems involving the computation of exact values of very large magnitude and p ...

随机推荐

  1. 九、xadmin菜单分组管理

    有的时候,我们的菜单很多很杂,想要把菜单进行分组以方便管理,如下 前一篇博文已经详细讲解了如何菜单自定义排序,自定义分组和排序其实写法类似: 要实现上面这个功能,分为以下几步: 1. 我们需要定义一个 ...

  2. Web 应用 WEB框架 HTTP协议 初识Django

    ----------------------------财富存在于人的思想里,你没找到路,不等于没有路,你想知道将来要得到什么,你必须知道现在应该先做什么和先放弃什么! [web 应用] web应用 ...

  3. Vue diff 算法

    一.虚拟 DOM (virtual dom) diff 算法首先要明确一个概念就是 diff 的对象是虚拟DOM(virtual dom),更新真实 DOM 是 diff 算法的结果. 注:virtu ...

  4. JSP 快速入门

    目录 生命周期 9大对象 常用指令 基本语法 表达式语言(EL) jstl介绍 常用的jstl标签 生命周期 我们虽然写的是jsp,代码中包含了html.css.js,以及Java代码,但是真正执行的 ...

  5. jquery中ajax使用

    JQuery的Ajax操作,对JavaScript底层Ajax操作进行了封装, <script type="text/javascript"> $.ajax({ url ...

  6. CMD管道命令使用

    Windows netstat 查看端口.进程占用 开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这个PID所对应的程序如果任务 ...

  7. [转帖]Stack的三种含义

    Stack的三种含义 http://www.ruanyifeng.com/blog/2013/11/stack.html 学习编程的时候,经常会看到stack这个词,它的中文名字叫做"栈&q ...

  8. MyBatis映射文件6

    之前说了由Employee找Department,这一节讲一讲由Department找Employee,显然前者是多对一的关系,而后者是一对多的关系. Department的JavaBean: pri ...

  9. Servlet学习的一些笔记

    Servlet一点笔记 Servlet:Server Applet,全称Java Servlet,是运行在Web服务器或应用服务器上的程序,它是作为来自Web浏览器或其他HTTP客户端的请求和HTTP ...

  10. export default用法

    // test.js export default { name: 'zs', age: 20 } 或是 // test.js var info = { name: 'zs', age: 20 } e ...