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

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. python文件、文件夹的移动、复制、删除、重命名

    import os.path ,shutil shutil.copytree("G://qqfile","G://new_qqfile")# 第一个是原来的文件 ...

  2. centos 7 network.service control process exited

    一.service network restart 出错 问题描述: vmware 12 下centos 7 网络模式,NAT 昨晚作者打算更新自己虚拟机python,发现没网络ping www.ba ...

  3. ibatis实战之插入数据(自动生成主键)

    ibatis实战之插入数据(自动生成主键) --------- 如果你将数据库设计为使用自动生成的主键,就可以使用ibatis的<selectKey>元素(该元素是<insert&g ...

  4. rest-framework频率组件

    throttle(访问频率)组件 1.局部视图throttle from rest_framework.throttling import BaseThrottle VISIT_RECORD={} c ...

  5. rest-framework的认证组件

    认证组件 1.登录认证(与组件无关): 首先要在model表内添加用户表和token表: from django.db import models # Create your models here. ...

  6. docker vm 性能优劣

    Docker容器与虚拟机区别 - unixfbi.com - 博客园 http://www.cnblogs.com/pangguoping/articles/5515286.html docker与虚 ...

  7. 使用jmeter来发送json/gzip格式数据 --------笔记

    一.使用jmeter来发送gzip数据 有时候我们需要模拟在客户端将数据压缩后, 发送(post)到服务器端. 通常这种情况,会发生在移动终端上. 这样做的好处, 是可以节省流量.  当然, 服务器返 ...

  8. WPF中任务栏只显示主窗口

    我们在用WPF开发的时候,常常会遇到在主窗口打开的情况下,去显示子窗口,而此时任务栏同时显示主窗口与子窗口.这样看起来很不美观.所以在弹出子窗口之前,设置它的几个相应属性,便不会出现这种问题了. // ...

  9. git客户端下载 和安装

    网址  https://git-scm.com/download/win 点击next 说明: (1)图标组件(Addition icons) : 选择是否创建桌面快捷方式. (2)桌面浏览(Wind ...

  10. Artifact project04:war :Error during artifact deployment. See server log for details

    困扰了我好长时间,我的错误是 先 Run clean  再package就成功了.