计算几何--POJ--1654--Area
2017-07-23 15:31
477 查看
Description
You are going tocompute the area of a special kind of polygon. One vertex of the polygon is theorigin of the orthogonal coordinate system. From this vertex, you may go stepby step to the following vertexes of the polygon until back to the initialvertex.
For each step you may go North, West, South or East with step length of1 unit, or go Northwest, Northeast, Southwest or Southeast with step length ofsquare root of 2.
For example, this is a legal polygon to be computed and its area is 2.5:
Input
The first line ofinput is an integer t (1 <= t <= 20), the number of the test polygons.Each of the following lines contains a string composed of digits 1-9 describinghow the polygon is formed by walking from the origin. Here 8, 2, 6 and 4represent
North, South, East and West, while 9, 7, 3 and 1 denote Northeast,Northwest, Southeast and Southwest respectively. Number 5 only appears at theend of the sequence indicating the stop of walking. You may assume that theinput polygon is valid which means that
the endpoint is always the start pointand the sides of the polygon are not cross to each other.Each line may containup to 1000000 digits.
Output
For each polygon,print its area on a single line.
Sample Input
4
5
825
6725
6244865
Sample Output
0
0
0.5
2
走一步算一步,不用算出来每个点,因为同向叉乘为0,不影响结果
You are going tocompute the area of a special kind of polygon. One vertex of the polygon is theorigin of the orthogonal coordinate system. From this vertex, you may go stepby step to the following vertexes of the polygon until back to the initialvertex.
For each step you may go North, West, South or East with step length of1 unit, or go Northwest, Northeast, Southwest or Southeast with step length ofsquare root of 2.
For example, this is a legal polygon to be computed and its area is 2.5:
Input
The first line ofinput is an integer t (1 <= t <= 20), the number of the test polygons.Each of the following lines contains a string composed of digits 1-9 describinghow the polygon is formed by walking from the origin. Here 8, 2, 6 and 4represent
North, South, East and West, while 9, 7, 3 and 1 denote Northeast,Northwest, Southeast and Southwest respectively. Number 5 only appears at theend of the sequence indicating the stop of walking. You may assume that theinput polygon is valid which means that
the endpoint is always the start pointand the sides of the polygon are not cross to each other.Each line may containup to 1000000 digits.
Output
For each polygon,print its area on a single line.
Sample Input
4
5
825
6725
6244865
Sample Output
0
0
0.5
2
走一步算一步,不用算出来每个点,因为同向叉乘为0,不影响结果
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> using namespace std; int dir[10][2]={0,0,-1,-1,0,-1,1,-1,-1,0,0,0,1,0,-1,1,0,1,1,1}; int main() { char a[1000005]; int t,i; cin>>t; while(t--) { scanf("%s",a); int l1=strlen(a); if(l1<3) { printf("0\n"); continue; } long long int x=0,y=0; long long int xx,yy; long long int are=0; for(i=0;i<l1-1;i++) { xx=x+dir[a[i]-'0'][0]; yy=y+dir[a[i]-'0'][1]; are=are+(xx*y-x*yy); x=xx; y=yy; } if(are<0) are=-are; if(are%2==0) cout<<are/2<<endl; else cout<<are/2<<".5"<<endl; } }
相关文章推荐
- poj 1654 Area ----- 计算几何
- [POJ1654]Area(计算几何-多边形的面积)
- (计算几何POJ step 8.1.1.2)POJ 1654 Area(使用叉积来计算多边形面积)
- Area poj 1654 计算几何
- POJ 1654 Area(计算几何)
- POJ 1654 Area 【叉乘+外积的几何意义】【计算几何】
- [POJ1654]Area(计算几何)
- poj 1654 Area(计算几何)
- poj1654 Area 计算几何
- POJ 1654 Area 计算几何
- POJ 1654 Area(计算几何)
- 【计算几何】poj 1654 Area
- poj1654 Area (计算几何)
- POJ 1654 Area计算几何(解题报告)
- poj1654—Area(计算几何求多边形面积)
- POJ 1654 Area 计算几何基础
- poj1654---计算几何
- POJ 1265-Area(计算几何+皮克定理+多边形面积公式)
- poj 1654(计算几何)(差乘运用)
- poj1265 Area(计算几何)