Area
| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 17456 |
|
Accepted: 4847 |
Description
You is going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orthogonal coordinate system. From this vertex, your may go step by step to the following vertexes of the polygon until back to the initial vertex. For each step to go north, West, south or East with step length of 1 unit, or go northwest, northeast, Southwest or S Outheast with step length of square root of 2.
For example, the is a legal polygon to being computed and its area is 2.5:
Input
The first line of input was an integer t (1 <= t <=), the number of the the test polygons. Each of the following lines contains a string composed of digits 1-9 describing how the polygon was formed by walking from The origin. Here 8, 2, 6 and 4 represent North, south, East and West, while 9, 7, 3 and 1 denote northeast, northwest, southeast and S Outhwest respectively. Number 5 is appears at the end of the sequence indicating the stop of walking. Assume that the input polygon are valid which means that the endpoint are always the start point and the sides of th E Polygon is not a cross to each of the other. contain up to 1000000 digits.
Output
For each polygon, the print its area in a single line.
Sample Input
4582567256244865
Sample Output
000.52
Source
POJ monthly--2004.05.15 Liu[email protected]
Ideas
Polygon to find area.
Cross product calculation.
Code
1#include <cstdio>2#include <cstring>3 using namespacestd;4 5typedefLong LongLL;6 Const intdx[Ten]={1,1,1,0,0,0,-1,-1,-1};7 Const intdy[Ten]={-1,0,1,-1,0,1,-1,0,1};8 9 LL ans;Ten Chars[1000010]; One A intMain () { - intT; -scanf"%d",&T); the while(t--) { -ans=0; -scanf"%s", s); - intnx=0, ny=0, x, y; + intL=strlen (s); - for(intI=0; i<l;i++) {//Why write directly strlen (s) will be tle =-= +x=nx+dx[s[i]-'1']; Ay=ny+dy[s[i]-'1']; atAns + = (x*ny-nx*y); -Nx=x, ny=y; - } - if(ans<0) ans=-ans; -printf"%lld", ans/2); - if(ans&1) printf (". 5"); inPutchar ('\ n'); - } to return 0; +}
POJ 1654 Area (polygon size)