2018.07.04 POJ 1654 Area(简单计算几何)
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(简单计算几何)的更多相关文章
- 2018.07.04 POJ 1265 Area(计算几何)
Area Time Limit: 1000MS Memory Limit: 10000K Description Being well known for its highly innovative ...
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- 2018.07.04 POJ 3304 Segments(简单计算几何)
Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dimensional ...
- poj 1654 Area(计算几何--叉积求多边形面积)
一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...
- 2018.07.04 POJ 1113 Wall(凸包)
Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...
- 2018.07.04 POJ 1696 Space Ant(凸包卷包裹)
Space Ant Time Limit: 1000MS Memory Limit: 10000K Description The most exciting space discovery occu ...
- poj 1654 Area 多边形面积
/* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...
- poj 1654 Area (多边形求面积)
链接:http://poj.org/problem?id=1654 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- 2018.07.03 POJ 2318 TOYS(二分+简单计算几何)
TOYS Time Limit: 2000MS Memory Limit: 65536K Description Calculate the number of toys that land in e ...
随机推荐
- 关于jquery的cookie的顺序,应首先是jQuery的引用,然后是cookie引用,否则系统无反应
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript" ></scri ...
- mongodb基础学习4-游标
今天来讲讲游标的操作,可以先获取一组文档,再对每一个文档进行操作. 因为mongodb底层是js引擎,所有可以像操作js一样操作mongodb,比如插入数据 游标的使用:声明游标,判断是否有下一条数据 ...
- 锋利的BFC
在初学前端的时候,我们会经常碰到各种各样的布局问题,尤其当使用浮动的时候,然而学习了BFC之后,其中的一些怪异现象,也因此成为理所当然,会有一种拨开云雾的快感. 下面简单介绍下BFC,究竟什么是BFC ...
- CDLinux制作成U盘启动
由于CDLinux在虚拟机跑的时候无法识别集成的笔记本网卡,故在此进行一下相关步骤的整理. 工具: U盘 UNetbootin 步骤: 1.插入U盘到电脑.不一定要在操作之前进行格式化,我目前的U盘分 ...
- sql server判断是否为null
sql server 替换null:isnull(arg,value) 如:select isnull(price,0.0) from orders ,如果price为null的话,用0.0替换 与n ...
- sessionStorage和localStorage
html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage. sessionStorage用于本地存储一个会话(session)中的数据,这些数据只 ...
- k-means处理图片
问题描述:把给定图片,用图片中最主要的三种颜色来表示该图片 k-means思想: 1.选择k个点作为初始中心 2.将每个点指派到最近的中心,形成k个簇cluster 3.重新计算每个簇的中心 4.如果 ...
- RabbitMQ 高可用集群搭建
面向EDA(事件驱动架构)的方式来设计你的消息 AMQP routing key的设计 RabbitMQ cluster搭建 Mirror queue policy设置 两个不错的RabbitMQ p ...
- https 证书传递、验证和数据加密、解密过程解析
我们都知道HTTPS能够加密信息,以免敏感信息被第三方获取.所以很多银行网站或电子邮箱等等安全级别较高的服务都会采用HTTPS协议. HTTPS简介 HTTPS其实是有两部分组成:HTTP + SSL ...
- Java工具类_表结构自动生成对应的实体类、Mapper.xml文件、Dao类
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWrit ...