UVA485 Pascal‘s Triangle of Death大数

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA485 Pascal‘s Triangle of Death大数相关的知识,希望对你有一定的参考价值。

In this problem, you are asked to generate Pascal’s Triangle. Pascal’s Triangle is useful in many areas from probability to polynomials to programming contests. It is a triangle of integers with “1” on top and down the sides. Any number in the interior equals the sum of the two numbers above it. For example, here are the first 5 rows of the triangle.

        1
      1 1
    1 2 1
  1 3 3 1
1 4 6 4 1

    In “Pascal’s Triangle of Death,” you are to generate a left justified Pascal’s Triangle. When any number in the triangle is exceeds or equals 1060, your program should finish printing the current row and exit. The output should have each row of the triangle on a separate line with one space between each element.
    The final element of each line should be directly followed by a newline. There is no space after the last number on each line.
Sample Input
There is no input for this problem.
Sample Output
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
.
.
.

问题链接UVA485 Pascal’s Triangle of Death
问题简述:(略)
问题分析:大数问题,打印杨辉三角。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的Java语言程序如下:

/* UVA485 Pascal's Triangle of Death */

import java.math.BigInteger;

public class Main {
	public static void main(String args[]) {
		BigInteger a[][] = new BigInteger[300][300];
		a[0][0] = BigInteger.ONE;
		for(int i = 1; i < 300;i++) {
			a[i][0] = BigInteger.ONE;
			for(int j = 1; j < i; j++)
				a[i][j] = a[i - 1][j - 1].add(a[i - 1][j]);
			a[i][i] = BigInteger.ONE;
		}
		BigInteger m = BigInteger.valueOf(10).pow(60);
		m = m.subtract(BigInteger.ONE);
		for(int i = 0; i < 300; i++) {
			int flag = 0;
			for(int j = 0; j <= i; j++) {
				if (m.compareTo(a[i][j]) == -1) flag = 1;
				if (j != 0) System.out.print(" ");
				System.out.print(a[i][j]);
			}
			System.out.println();
			if(flag == 1) break;
		}
	}
}```

以上是关于UVA485 Pascal‘s Triangle of Death大数的主要内容,如果未能解决你的问题,请参考以下文章

118. Pascal's Triangle

119. Pascal's Triangle II

119. Pascal's Triangle II

118. Pascal's Triangle@python

Pascal&#39;s Triangle II

118. Pascal's Triangle