zoukankan      html  css  js  c++  java
  • 【HDOJ6222】Heron and His Triangle(Java,二分,递推)

    题意:让你找这样的一个三角形,三条边为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      }
  • 相关阅读:
    杜教筛学习笔记
    AtCoder Beginner Contest 188 F
    求和公式
    洛谷P4848 崂山白花蛇草水 权值线段树+KDtree
    二次剩余学习笔记
    Miller Rabin素数检测与Pollard Rho算法
    半平面交学习笔记
    凸包习题总结
    多项式半家桶
    CF997解题报告
  • 原文地址:https://www.cnblogs.com/myx12345/p/9747511.html
Copyright © 2011-2022 走看看