HDUOJ2036: reform spring breeze Montreal

Copyright: qq836678589 https://blog.csdn.net/weixin_43924623/article/details/90712529

Reform spring breeze Montreal

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 49280 Accepted Submission(s): 25173

The Description Problem
"spring breeze of reform over the floor,
not AC does not matter;
it is not to return home,
as well as third of an acre.
Thank you (band play music)!"

Some students saying excellent state of mind, I know the game every day, the exam so simple subject, but also foggy, but also turned out to be so few limericks.
Okay, the teacher's responsibility is to help you solve the problem, since it would like to farm, it points you one.
This field is located in Cangnan County of Wenzhou City, Zhejiang Province Lingxi Linjiapuzi village, polygon-shaped piece of land, originally linle now ready to give you. However, everything is not so simple, you must first tell me how much of the land area in the end, if answered correctly in order to really get the land.
Worry about, right? Is to let you know, farming is also a need AC knowledge! After it was good practice ...

Input
input data comprising a plurality of test cases, one row for each test case, the beginning of each line is an integer n (3 <= n <= 100), which represents the number of polygon (of course, the number of vertices) edge, then in accordance with n counterclockwise order given vertex coordinates (x1, y1, x2, y2 ... xn, yn), in order to simplify the problem, where all coordinates are represented by integer.
The input data are all integers in the range of 32-bit integers, n = 0 indicates the end of the data without processing.

Output
For each test case, output a polygon area corresponding to the result of a decimal decimal place.
The output of each instance per line.

Sample Input
3 0 0 1 0 0 1
4 1 0 0 1 -1 0 0 -1
0

Sample Output
0.5
2.0

#include<iostream>
using namespace std;
int main(){
	int n,temp,i;
	float s;
	int x[101],y[101];
	while(cin>>n && n!=0){
		temp=0;
		for(i=1;i<=n;i++)
			cin>>x[i]>>y[i];
		for(i=1;i<=n;i++){
			if(i<n)
				temp=temp+x[i]*y[i+1]-y[i]*x[i+1];
			else
				temp=temp+x[i]*y[1]-y[i]*x[1];
		}
		s = 0.5*abs(temp);
		printf("%.1f\n",s);
	}
	return 0;
}

Note i starting at 1.

Guess you like

Origin blog.csdn.net/weixin_43924623/article/details/90712529