hdu 6222 Heron and His Triangle ###K ###K //K

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222

题意:问边长为t-1 t t+1 这样的三角形 的面积为整数的 这样的t   给定n  问最小的t大于n的是多少

思路:打表规律题,  用三角形的海伦公式 p=(a+b+c)/2  S=sqrt(p*(p-a)*(p-b)*(p-c))  注意通分一下化成整数 然打下表技能找到规律

发现f[i]=4*f[i-1]-f[i-2]  但是要大数 所以用java写

 1 import java.math.BigInteger;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5     public static void main(String[] args) 
 6     {
 7         int t;
 8         Scanner in=new Scanner(System.in);
 9         t=in.nextInt();
10         BigInteger f[]=new BigInteger[105];
11         f[0]=BigInteger.valueOf(4);
12         f[1]=BigInteger.valueOf(14);
13         for(int i=2;i<=100;i++)
14         {
15             BigInteger p=f[i-1].multiply(f[0]);
16             f[i]=p.subtract(f[i-2]);
17         }
18         
19         for(int i=0;i<t;i++)
20         {
21             BigInteger c=in.nextBigInteger();
22             for(int j=0;j<=100;j++)
23             {
24                 if(f[j].compareTo(c)>=0)
25                 {
26                     System.out.println(f[j]);
27                     break;
28                 }
29             }
30         }
31         
32         
33     }
34 
35 }
View Code

 

posted @ 2020-09-27 08:42  canwinfor  阅读(161)  评论(0)    收藏  举报