The king of Fancyland has bought a piece of land that's in an area which is made from pieces of square shape. The price of the land if being measured by the number of the whole square-shaped pieces [fields] which are on the parcel. Due to this, it's easier to calculate the price of the parcel in Fancyland than in Yukiland. [that’s another random country in the task]. Your task is to write a program which will calculate the price of the parcel which is bought. Pieces of the field which make [form] the parcel form a closed polygon which apexes are corners of square fields. For example, polygon from the picture [which fits the first from the three examples] contains three square fields [square-shaped fields, so its value [price] is 3.
Input
In the first line of standard input is a whole number N [whole number is 3,4,5 and so, not 0,75 or 1/4 and so]
(3<=N<=100). N is the number of apexes of the polygon. In every line of the following N lines there are couples of whole numbers Xi and Yi, coordinates of i-th apex of the polygon. The apexes are given in order in which they appear in the perimeter of the polygon. You can suppose that there won't be coordinates lesser than [under] -500 or bigger [above] 500 and that the polygon will be convex. [because the law in Fancyland says so]
OUTPUT
The output has to contain only one line in which there is one whole number [the price (value) of the parcel (piece of land) that is bought. The price equals the number of whole square-shaped fields in it.
Input
4
1 1
5 3
5 4
3 5
Output:
3
Input
5
3 3
2 5
3 4
5 2
4 2
Output:
0
Input:
5
0 0
0 -50
-50 -51
-51 -50
-50 0
Output:
2500
8 replies to this topic
#1
Posted 12 February 2011 - 06:30 AM
|
|
|
#2
Posted 12 February 2011 - 06:50 AM
It looks like this is homework. Given that, what part are you having difficulties with? What have you coded so far?
#3
Posted 12 February 2011 - 06:59 AM
Nothing, really nothing. I have to solve this, and another 4 tasks till 8 pm [Central European time] or I will probably fail a grade of something like that. But I haven't studied anything and now I'm begging for anyone to help me! D: Practically, I'm looking for anyone who would be so kind to write those few programs for me, and in return I'll be grateful forever.
#4
Posted 12 February 2011 - 07:15 AM
And I can solve the problems in C or C++ too...
#5
Posted 12 February 2011 - 07:30 AM
We don't do people's homework for them. We help people do their own homework.
With that said: First you have to be able to open the file to read the input. The first line is an integer, each additional line goes into an array of x's and y's.
Have you grabbed a piece of paper to plot out the coordinates that are inputted? Your output is NOT the area of the polygon, it is the number of 1x1 squares that are located entirely within the polygon. See this example of the first input.[ATTACH=CONFIG]3703[/ATTACH]
With that said: First you have to be able to open the file to read the input. The first line is an integer, each additional line goes into an array of x's and y's.
Have you grabbed a piece of paper to plot out the coordinates that are inputted? Your output is NOT the area of the polygon, it is the number of 1x1 squares that are located entirely within the polygon. See this example of the first input.[ATTACH=CONFIG]3703[/ATTACH]
#6
Posted 12 February 2011 - 07:55 AM
We haven't even studied arrays at school.
#7
Posted 12 February 2011 - 08:50 AM
What have you studied?
#8
Posted 12 February 2011 - 08:56 AM
Only linear type of tasks.
#9
Posted 12 February 2011 - 01:27 PM
You need to know how to use loops, file access, and arrays. If you haven't studied those, there is something VERY wrong with this assignment.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









