UVA10519 Really Strange大数+递推

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10519 Really Strange大数+递推相关的知识,希望对你有一定的参考价值。

Raju has recently passed BSc. Engineering in Computer Science & Engineering from BUET (Bangladesh University of Extraordinary Talents), the best university of Bangladesh. After passing, he has been appointed manager of BCS (Bangladesh Calculation Society ). His first project is to visit a district and then to report the total number of distinct regions there. But, going there, he is astonished to see a very strange phenomena of the local people. He discovered that, the people make their area circular. Every two area have exactly two points to intersect and no three circles intersect in a common point. There are so many people so that it’s very hard to calculate total number of distinct regions for Raju. So, only in this case he seeks for your help.

Input
The problem contains multiple test cases. You are given total number of circular area n in separate lines (n ≤ 10100). And you know the number houses in the world can’t be fraction or negative. Input is terminated by end of file.
Output
For each line of the input, your correct program should output the value of the total number of regions in separate lines for each value of n.
Sample Input
3
4
Sample Output
8
14

问题链接UVA10519 !! Really Strange !!
问题简述:(略)
问题分析:第n个圆与前n-1个圆共有2*(n-1)个交点,生成2*(n-1)个新区域,得递推式f(n)=f(n-1)+2*(n-1),推导得f(n)=n^2-n+2,f(0)=1。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的Java语言程序如下:

/* UVA10519 !! Really Strange !! */

import java.math.BigInteger;
import java.util.Scanner;

public class Main 
	public static void main(String[] args) 
        Scanner cin = new Scanner(System.in);
        BigInteger n;
        while (cin.hasNext()) 
            n = cin.nextBigInteger();
            if(n.equals(BigInteger.ZERO))
                System.out.println("1");
            else 
                n = n.multiply(n).add(n.negate()).add(BigInteger.valueOf(2));
                System.out.println(n);
            
        
        cin.close();
    

创作打卡挑战赛 赢取流量/现金/CSDN周边激励大奖

以上是关于UVA10519 Really Strange大数+递推的主要内容,如果未能解决你的问题,请参考以下文章

UVA10328 Coin TossDP+大数

UVa 495大数加法

UVA10157 Expressions大数+递推

UVA10157 Expressions大数+递推

UVA10328 Coin TossDP+大数

Uva-oj Product 大数乘法