HDU2050 Polyline Split Plane Problem Solving Report

Reprinted from: http://blog.csdn.net/a576323437/article/details/6163850

Title: http://acm.hdu.edu.cn/showproblem.php?pid=2050

We have seen many problems of dividing planes by straight lines. Today's problem is slightly changed. What we require is the maximum number of planes divided by n polylines. For example, a polyline can divide a plane into two parts, and two polylines can divide a plane into up to 7 parts.

Problem solving ideas:

1 Recursion, first analyze the situation of dividing the plane by a straight line. When adding the nth straight line, there are at most n-1 intersections with the previous straight line, and the divided part is more than (n-1)+1. ;

The same is true for 2 polylines, f(1)=2, f(2)=7, first draw the first n-1 polylines, when adding the nth strip, the new intersection with the graph is at most 2* 2(n-1), so the divided part is more than 2*2(n-1)+1, so f(n)=f(n-1)+4*(n-1)+1, n>=3

[cpp]  view plain copy  
  1. #include <stdio.h>  
  2. intmain  ()  
  3. {  
  4.     int n,i,k,j;  
  5.     __int64 a[10010];  
  6.     scanf("%d",&n);  
  7.     for(i=1;i<=n;i++)  
  8.     {  
  9.         scanf("%d",&k);  
  10.         a[1]=2;  
  11.         for(j=2;j<=k;j++)  
  12.             a[j]=a[j-1]+4*(j-1)+1;  
  13.         printf("%I64d\n",a[k]);  
  14.     }  
  15.     return 0;  
  16. }  

import java.util.Scanner;

public class HDU2050 {
	static Long[] f = new Long[10000+10];
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		dfs();
		int t = in.nextInt();
		while (t-- != 0) {
			int n = in.nextInt();
			System.out.println(f[n]);
		}
	}
	public static void dfs() {
		f[1] = 2L;
		f[2] = 7L;
		for (int i = 3; i < 10000+10; i++) {
			f[i] = f[i - 1] + 4*(i-1) + 1;
		}
	}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325597478&siteId=291194637