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 ...
随机推荐
- margin-top和padding-top
padding- top 在原有的基础上进一步的扩张 margin - top 在原有的位置上发生上下的平移 <!DOCTYPE html> <html lang="en& ...
- shutil模块(高级的文件copy)
import shutil import os f1 = open('本节笔记.txt', encoding = 'utf-8') f2 = open('笔记2', 'w', encoding = ' ...
- 前端-CSS-介绍及三种引入方式
我们为什么需要CSS? 使用css的目的就是让网页具有美观一致的页面,另外一个最重要的原因是内容与格式分离 在没有CSS之前,我们想要修改HTML元素的样式需要为每个HTML元素单独定义样式属性,当H ...
- HTTP状态码 解析
原文地址:HTTP状态码:400500错误代码(个人总结)作者:lining2008net 一些常见的状态码为: 200-服务器成功返回网页 404-请求的网页不存在 503-服务不可用 详细分解: ...
- centoros 环境安装
1. nginx rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.no ...
- 程序员教程-10章-C++程序设计
本来这章是不打算写了的,毕竟自己学的是JAVA,C++就不想看了,但毕竟还有一点时间,就把C++也看一下吧 目录结构 10.1 C++程序基础 10.1.1 数据类型 1 基本数据类型 2 常量和变量 ...
- No matter how hard it is or no matter how bad it gets, I am going to make it!
No matter how hard it is or no matter how bad it gets, I am going to make it! He always had a yearni ...
- C# split分割多个字符
string[] myAgent = agentInfo.Split(new string[] { "$#$" }, StringSplitOptions.None);
- go语言中make和new的区别
make用于内建类型(map.slice 和channel)的内存分配.new用于各种类型的内存分配. 内建函数new本质上说跟其他语言中的同名函数功能一样:new(T)分配了零值填充的T类型的内存空 ...
- Codeforces Beta Round #12 (Div 2 Only)
Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...