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语言程序如下:
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();
}
}
|