UVA – 10079 – Pizza Cutting

  • ID: UVA – 10079 – Pizza Cutting
  • Difficulty : Geometric Intuition
  • Type : Geometry.
  • Description :
    • Each new line you add to the circle can be put to cut all the previous lines. ( fact )
    • if the line crossed n lines then it added new n+1 slices. ( draw it to get it )
    • then if  p parts exist and we add new line we have p + n+1 where n is the previous no of lines existed. ( intution )
    • then the recurrence formula is defined as follows p( i ) = p( i-1 ) + i;
    • can’t you see it’s the arithematic sequence sum ?
  • Code:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long N;
		while((N =in.nextLong()) >=0){
			long S = (N*(N+1))/2 +1;
			System.out.println(S);
		}
	}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: