hdu5047 Sawtooth 规律 + JAVA大数

探讨了使用特定形状的锯齿图形(形似字母'M')将平面划分为最多区域的问题。给出了数学公式来计算不同数量的这些图形可以划分出的最大区域数,并提供了Java实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sawtooth

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2272    Accepted Submission(s): 834


Problem Description
Think about a plane:

● One straight line can divide a plane into two regions.
● Two lines can divide a plane into at most four regions.
● Three lines can divide a plane into at most seven regions.
● And so on...

Now we have some figure constructed with two parallel rays in the same direction, joined by two straight segments. It looks like a character “M”. You are given N such “M”s. What is the maximum number of regions that these “M”s can divide a plane ?

 

Input
The first line of the input is T (1 ≤ T ≤ 100000), which stands for the number of test cases you need to solve.

Each case contains one single non-negative integer, indicating number of “M”s. (0 ≤ N ≤ 10 12)
 

Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then an integer that is the maximum number of regions N the “M” figures can divide.
 

Sample Input
  
  
2 1 2
 

Sample Output
  
  
Case #1: 2 Case #2: 19
 


f(n) = 8 * n * n - 7 * n + 1


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedInputStream(System.in));
		PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		int T, kase;
		T = in.nextInt();
		kase = 0;
		BigInteger n, ans;
		while (T-- != 0) {
			n = in.nextBigInteger();
			ans = BigInteger.valueOf(8).multiply(n).multiply(n).subtract(BigInteger.valueOf(7).multiply(n))
			.add(BigInteger.ONE);
			out.printf("Case #%d: ", ++kase);
			out.println(ans.toString());
		}
		
		in.close();
		out.close();
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值