HDU 2036 reform spring breeze

Source: Internet
Author: User

/*
Question:
Chinese Translation:
Calculate the area of a piece of land
Solution:
Difficulties: In my understanding of the following formula, we can bring these two points out of the origin to form a triangular area with the origin. The last vertex must be combined with the first vertex. Therefore, when writing a program, you need to separate the last vertex and combine it with the first vertex.
Key point: the formula for calculating the area of an irregular polygon is 0.5*(x1 * Y2-X2 * Y1). It is also easier to use a struct to input coordinate data.
Problem solving person: lingnichong
Solution time: 16:42:20

Problem-solving experience: I don't know how painful it is to find an irregular polygon area!
*/


Spring Breeze of Reform Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 18488 accepted submission (s): 9451


Problem description,
No AC;
I can't go back to my hometown,
There is also an acre of three sub-regions.
Thank you! (Band music )"

In other words, some students have a very good mentality and know about the game every day. The simple question of this test is also in the fog of the cloud. In addition, there are just a few poems.
Well, the teacher's responsibility is to help you solve the problem. If you want to farm your work, you can divide it into one.
This field is located in linjiabaozi village, lingxi town, Cangnan County, Wenzhou City, Zhejiang province, with a Polygon Shape. It was originally linle and is ready for you now. However, nothing is so simple. You must first tell me how much area the land actually has. If the answer is correct, you can really get the land.
Worried? It's just to let you know that it also requires AC knowledge to farm land! Try again later...
 
Input data contains multiple test instances. Each test instance occupies one row. Each row starts with an integer N (3 <=n <= 100 ), it represents the number of edges of a polygon (of course also the number of vertices), and then the coordinates of N vertices (x1, Y1, X2, y2... XN, yn). To simplify the problem, all coordinates here are represented by integers.
All the integers in the input data are within the 32-bit integer range. n = 0 indicates the end of the data and is not processed.
 
For each test instance, output the corresponding polygon area. The result is precise to the decimal place.
The output of each instance occupies one row.
 
Sample Input
3 0 0 1 0 0 14 1 0 0 1 -1 0 0 -10
 
Sample output
0.52.0
 


#include<stdio.h>struct point{int x;int y;}p[110];int main(){int n,i;double area;while(scanf("%d",&n),n){area=0;for(i=0;i<n;i++)scanf("%d%d",&p[i].x,&p[i].y);for(i=0;i<n-1;i++)area=area+0.5*(p[i].x*p[i+1].y-p[i].y*p[i+1].x);area=area+0.5*(p[n-1].x*p[0].y-p[n-1].y*p[0].x);printf("%.1lf\n",area);}return 0;} 






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.