Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How Many Pieces of Land ?
08-17-2009, 11:40 PM (This post was last modified: 10-29-2009 09:26 PM by drdebcol.)
Post: #1
How Many Pieces of Land ?
You are given an elliptical-shaped land and you are asked to choose n arbitrary points on its boundary. Then you connect each point with every other point using straight lines, forming n(n − 1)/2 connections. What is the maximum number of pieces of land you will get by choosing the points on the boundary carefully?
[Image: landdivision.JPG]
Input
The first line of the input file contains one integer s (0 < s < 3, 500), which indicates how many input instances there are. The next s lines describe s input instances, each consisting of exactly one integer n (0 ≤ n < 231).
Output
For each input instance output the maximum possible number pieces of land defined by n points, each printed on its own line.
Sample Input
4
1
2
3
4
Sample Output
1
2
4
8
Solution
Code:
program how_many_pieces_of_land;
uses wincrt;
var
  s:longint;
  i:integer;
  a:array[1..3500] of longint;
function power(n,k:longint):real;
var
   i:longint;
   r:real;
begin
   if k=1 then
    power:=1
   else
   begin
   r:=1;
  for i:=1 to k-1 do
    r:=r*n;
  power:=r;
  end;
end;
begin
  readln(s);
  for i:=1 to s do
  readln(a[i]);
  for i:=1 to s do
  writeln(round(power(2,a[i])));
end.

"I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein
Visit this user's website Find all posts by this user
Quote this message in a reply
08-17-2009, 11:52 PM
Post: #2
RE: How Many Pieces of Land ?
Sounds like an artificial intelligence problem. Will look at it tonight....G4143
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: