博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ACM 2017沈阳区域赛 Heron and His Triangle (找规律 Java大数)
阅读量:2135 次
发布时间:2019-04-30

本文共 2243 字,大约阅读时间需要 7 分钟。

 HDU - 6222   

题目大意:

(HDU的题面有乱码)

       给出一个n,需要找到t>=n,使得以长度为t-1 ,t ,t+1的三条边构成的三角形面积为整数,问最小的t是多少

      n为1e30

题解:

知道三角形三边求面积用海伦公式

S=\sqrt{p*(p-a)*(p-b)*(p-c)}

p=\frac{a+b+c}{2}

将三边长t-1 ,t ,t+1带入得

S=\frac{t}{4}\sqrt{3*(t-2)*(t+2)}

所以只要判断一下3(t-2)(t+2)是不是完全平方数就可以了

打表看了一下

1-----2

2-----2
3-----4
4-----4
5-----14
6-----14
7-----14
8-----14
9-----14
10-----14
11-----14
12-----14
13-----14
14-----14
15-----52
16-----52
17-----52
18-----52
19-----52
20-----52
21-----52
22-----52
23-----52
24-----52
25-----52
26-----52
27-----52
28-----52
29-----52
30-----52
31-----52
32-----52
33-----52
34-----52
35-----52
36-----52
37-----52
38-----52
39-----52
40-----52
41-----52
42-----52
43-----52
44-----52
45-----52
46-----52
47-----52
48-----52
49-----52
50-----52
51-----52
52-----52
53-----194
54-----194
55-----194
56-----194
57-----194
58-----194
59-----194
60-----194
61-----194
62-----194
63-----194
64-----194
65-----194
66-----194
67-----194
68-----194
69-----194
70-----194
71-----194
72-----194
73-----194
74-----194
75-----194
76-----194
77-----194
78-----194
79-----194
80-----194
81-----194
82-----194
83-----194
84-----194
85-----194
86-----194
87-----194
88-----194
89-----194
90-----194
91-----194
92-----194
93-----194
94-----194
95-----194
96-----194
97-----194
98-----194
99-----194
100-----194

前2项是不对的,应该都是4,所以肯定是有规律的

本地OEIS了一下(因为本人不太善于找规律emmmm相信比赛的时候队友是可以找出规律的)

是这个规律

于是就开始Java写了

循环到200其实数就已经足够大了

import java.io.*;import java.math.BigInteger;import java.util.*;public class Main {	public static void main(String[] args)	{		BigInteger[] f = new BigInteger[1500] ;		f[0]=new BigInteger("2");		f[1]=new BigInteger("4");		for(int i=2;i<=1000;++i)		{			//f[i]=4*f[i-1]+f[i-2];			f[i]=f[i-1].multiply(f[1]);			f[i]=f[i].subtract(f[i-2]);		}		Scanner input=new Scanner(System.in);		int t=input.nextInt();		while(t-->0)		{			BigInteger n=input.nextBigInteger();			for(int i=1;i<=1000;++i)				if(n.compareTo(f[i])<=0)				{					System.out.println(f[i]);					break;				}		}	}}

打表程序

#include 
#include
#include
#include
using namespace std;bool pd(int x){ int t=sqrt(x); if(t*t==x) return 1; return 0;}int main(){ for(int n=1; n<=1000; ++n) { for(int t=n;; ++t) { if(pd(3*(t-2)*(t+2))) { cout<
<<"-----"<
<

 

你可能感兴趣的文章
TP5.1事务操作和TP5事务回滚操作多表
查看>>
composer install或composer update 或 composer require phpoffice/phpexcel 失败解决办法
查看>>
TP5.1项目从windows的Apache服务迁移到linux的Nginx服务需要注意几点。
查看>>
win10安装软件 打开时报错 找不到 msvcp120.dll
查看>>
PHPunit+Xdebug代码覆盖率以及遇到的问题汇总
查看>>
PHPUnit安装及使用
查看>>
PHP项目用xhprof性能分析(安装及应用实例)
查看>>
composer安装YII
查看>>
Sublime text3快捷键演示
查看>>
sublime text3 快捷键修改
查看>>
关于PHP几点建议
查看>>
硬盘的接口、协议
查看>>
VLAN与子网划分区别
查看>>
Cisco Packet Tracer教程
查看>>
02. 交换机的基本配置和管理
查看>>
03. 交换机的Telnet远程登陆配置
查看>>
微信小程序-调用-腾讯视频-解决方案
查看>>
phpStudy安装yaf扩展
查看>>
密码 加密 加盐 常用操作记录
查看>>
TP 分页后,调用指定页。
查看>>