标签:直接 ring com rgs heron str ++ e30 一个
题意:让你找这样的一个三角形,三条边为t,t-1,t+1,并且面积为整数,最后满足t大于等于n。
n<=1e30
思路:直接推式子不会,打表找规律
f(n)=4*f(n-1)-f(n-2)(n>=3)
f(1)=4 f(2)=14
队友用Java写的,再写个二分就行
1 import java.math.BigInteger; 2 import java.util.Arrays; 3 import java.util.Scanner; 4 5 6 public class Main { 7 public static void main(String[] args){ 8 int t; 9 BigInteger[] a = new BigInteger[110]; 10 BigInteger n; 11 Scanner sc = new Scanner(System.in); 12 //System.out.println(new BigInteger("11").compareTo(new BigInteger("9"))); 13 a[1] = new BigInteger("4"); 14 a[2] = new BigInteger("14"); 15 a[3] = new BigInteger("52"); 16 for(int j = 4; j <= 100; ++j){ 17 a[j] = a[j - 1].multiply(new BigInteger("4")).subtract(a[j - 2]); 18 } 19 t = sc.nextInt(); 20 for(int i = 1; i <= t; ++i){ 21 n = sc.nextBigInteger(); 22 //System.out.println(n); 23 for(int j = 1; j <= 100; ++j){ 24 if(a[j].compareTo(n) >= 0){ 25 System.out.println(a[j]); 26 break; 27 } 28 } 29 } 30 }
【HDOJ6222】Heron and His Triangle(Java,二分,递推)
标签:直接 ring com rgs heron str ++ e30 一个
原文地址:https://www.cnblogs.com/myx12345/p/9747511.html