计算几何--POJ--1654--Area
来源:互联网 发布:犀牛软件 下载 编辑:程序博客网 时间:2024/06/08 06:57
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,不影响结果
#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;elsecout<<are/2<<".5"<<endl;}}
- 【计算几何】poj 1654 Area
- Area poj 1654 计算几何
- 计算几何--POJ--1654--Area
- poj 1654 Area(计算几何)
- POJ 1654 Area(计算几何)
- POJ 1654 Area(计算几何)
- POJ 1654 Area 计算几何基础
- POJ 1654 Area计算几何(解题报告)
- POJ 1265 Area(计算几何--网格)
- (计算几何POJ step 8.1.1.2)POJ 1654 Area(使用叉积来计算多边形面积)
- POJ 1654 Area 【叉乘+外积的几何意义】【计算几何】
- poj 1265 Area 计算几何Pick定理 && poj 2954 Triangle
- hdu1071The area(计算几何)
- poj1654 Area 计算几何
- POJ 1654 Area 几何(叉积求多边形面积)
- POJ 1265 Area (计算几何)(Pick定理)
- POJ 1927 Area in Triangle(计算几何)
- POJ 2546 Circular Area [相交园面积]【计算几何】
- Sketch设置透明背景
- Oracle大数据常见优化查询
- PAT B1005. 继续(3n+1)猜想
- 【ACF学习】ACF训练检测模型
- B+树和LSM比较
- 计算几何--POJ--1654--Area
- Android知识点:监听链接、桌面快捷方式
- 设计模式六大原则
- 第一行代码 第7章 内容提供器 -- 运行时权限
- C语言学习小结--参数个数可变的函数
- 【Git零基础教程】(7)改写历史(Rewriting History)
- 【Java】文件复制的各种姿势
- 放大镜
- 在使用inline-block时遇到的元素之间的间隔