Area

Time Limit: 1000MS Memory Limit: 10000K

Description

You are 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, you may go step by step to the following vertexes of the polygon until back to the initial vertex. For each step you may go North, West, South or East with step length of 1 unit, or go Northwest, Northeast, Southwest or Southeast with step length of square root of 2.

For example, this is a legal polygon to be computed and its area is 2.5:



Input

The first line of input 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 describing how the polygon is 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 Southwest respectively. Number 5 only appears at the end of the sequence indicating the stop of walking. You may assume that the input polygon is valid which means that the endpoint is always the start point and the sides of the polygon are not cross to each other.Each line may contain up 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

Source

POJ Monthly–2004.05.15 Liu Rujia@POJ

一道基础计算几何题,就是在一串烦人的输入处理之后求组成的多边形面积,直接叉积算就好了。但要注意这题答案要开longlonglong longlonglong不然会WAWAWA(本蒟蒻亲身经历)

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 10000005
using namespace std;
struct pot{long long x,y;}p[3];
long long dx[10]={0,1,1,1,0,0,0,-1,-1,-1},dy[10]={0,-1,0,1,-1,0,1,-1,0,1},t,n;
long long ans;
inline long long cross(pot a,pot b){return a.x*b.y-a.y*b.x;}
char s[N];
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%s",s+1);
		n=strlen(s+1);
		p[0].x=p[0].y=0;
		p[1]=p[2]=p[0];
		ans=0;
		for(int i=1;i<n;++i){
			p[1]=p[2];
			p[2].x=p[1].x+dx[s[i]-'0'],p[2].y=p[1].y+dy[s[i]-'0'];
			ans+=cross(p[1],p[2]);
		}
		if(ans<0)ans=-ans;
		if(ans&1)printf("%lld.5\n",ans>>1);
		else printf("%lld\n",ans>>1);
	}
	return 0;
}

2018.07.04 POJ 1654 Area(简单计算几何)的更多相关文章

  1. 2018.07.04 POJ 1265 Area(计算几何)

    Area Time Limit: 1000MS Memory Limit: 10000K Description Being well known for its highly innovative ...

  2. 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)

    Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...

  3. 2018.07.04 POJ 3304 Segments(简单计算几何)

    Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dimensional ...

  4. poj 1654 Area(计算几何--叉积求多边形面积)

    一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...

  5. 2018.07.04 POJ 1113 Wall(凸包)

    Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...

  6. 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)

    Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...

  7. poj 1654 Area 多边形面积

    /* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...

  8. poj 1654 Area (多边形求面积)

    链接:http://poj.org/problem?id=1654 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  9. 2018.07.03 POJ 2318 TOYS(二分+简单计算几何)

    TOYS Time Limit: 2000MS Memory Limit: 65536K Description Calculate the number of toys that land in e ...

随机推荐

  1. leetcode504

    public class Solution { public string ConvertToBase7(int num) { ? "" : "-"; var ...

  2. 浅谈实体类为什么要实现Serializable接口?

    序列化 (Serialization)将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写入到临时或持久性存储区.以后,可以通过从存储区中读取或反序列化对象的状态,重新创 ...

  3. tensorflow笔记之滑动平均模型

    tensorflow使用tf.train.ExponentialMovingAverage实现滑动平均模型,在使用随机梯度下降方法训练神经网络时候,使用这个模型可以增强模型的鲁棒性(robust),可 ...

  4. Qt使用MSVC编译器不能正确显示中文的解决方案

    用VisualStudio做为IDE,使用Qt框架,显示中文,会出现乱码的情况. 原因:MSVC编译器虽然可以正常编译带BOM的UTF-8编译的源文件,但是生成的可执行文件的编码是Windows本地字 ...

  5. Elasticsearch之启动(前台和后台)

    分为两种情况,取决于是否安装了tomat. 一.若安装了tomcat 1.es的前台启动 需要先启动tomcat,再启动es,否则会报错! 所以,得 2.es的后台启动 [hadoop@HadoopM ...

  6. cobbler全自动批量安装部署linux

    Cobbler的设计方式: Cobbler的配置结构基于一组注册的对象.每个对象表示一个与另一个实体相关联的实体(该对象指向另一个对象,或者另一个对象指向该对象).当一个对象指向另一个对象时,它就继承 ...

  7. 使用Jena执行SPARQL的Select和Ask查询

    使用Jena执行SPARQL的Select和ask查询 提供基本的接口和实现类,可在其他代码中直接调用 Select查询 接口 /** * The interface Select dao. * 本体 ...

  8. 安装oracle后java -version命令显示 jdk version "1.3.1"的原因

    因为先装的JDK,后装了oracle,oracle的JDK配置把原来的jdk路径替换掉了. 我的电脑->属性->高级->环境变量->系统变量->PATH ,把JDK的路径 ...

  9. c++实现贪食蛇

    今天老师布置了作业 让我们观察c++实现贪食蛇的代码 #include<windows.h> #include<time.h> #include<stdlib.h> ...

  10. js中怎么写自执行函数

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...