Area
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17937   Accepted: 4957

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 题意:输入一个长为n字符串,前n-1个字符分别为1-4,6-9中的某个数字,最后一个数字5代表输入的结束,除了5以外
每个点都代表了一个方向,问这些点组成的面积是多少??
分析:设从(0,0)出发,然后将每个点记录下来,然后利用叉积求解多边形面积。(这里要用滚动数组优化)
最重要的一点是一定一定要记得用long long 不能用double 我是被坑到死。。。
///题意:输入一个长为n字符串,前n-1个字符分别为1-4,6-9中的某个数字,最后一个数字5代表输入的结束,除了5以外
///每个点都代表了一个方向,问这些点组成的面积是多少??
///分析:设从(0,0)出发,然后将每个点记录下来,然后利用叉积求解多边形面积。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
const double esp = 1e-;
struct Point{
long long x,y;
}p[]; long long mult(Point a,Point b){
return (a.x*b.y-a.y*b.x);
}
char str[N];
int dir[][]={{,},{-,-},{,-},{,-},{-,},{,},{,},{-,},{,},{,}};
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%s",str+);
int len = strlen(str+);
if(len==) {printf("0\n");continue;}
p[].x = dir[str[]-''][];
p[].y = dir[str[]-''][];
long long area = ;
for(int i=;str[i]!='';i++){
p[i%].x = dir[str[i]-''][]+p[(i-)%].x;
p[i%].y = dir[str[i]-''][]+p[(i-)%].y;
area+=mult(p[i%],p[(i-)%]);
}
//printf("%lf\n",area);
if(area<) area=-area;
/*
if(0.5-(area-(int)(area))<esp)
printf("%.1lf\n",area);
else printf("%.0lf\n",area);*/
printf ("%I64d", area/);
if (area%) printf (".5");
printf ("\n");
}
return ;
}

poj 1654(利用叉积求面积)的更多相关文章

  1. POJ - 1654 利用叉积求三角形面积 去 间接求多边形面积

    题意:在一个平面直角坐标系,一个点总是从原点出发,但是每次移动只能移动8个方向的中的一个并且每次移动距离只有1和√2这两种情况,最后一定会回到原点(以字母5结束),请你计算这个点所画出图形的面积 题解 ...

  2. POJ 1408 Fishnet【枚举+线段相交+叉积求面积】

    题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  3. 两条线段求交点+叉积求面积 poj 1408

    题目链接:https://vjudge.net/problem/POJ-1408 题目是叫我们求出所有四边形里最大的那个的面积. 思路:因为这里只给了我们正方形四条边上的点,所以我们要先计算横竖线段两 ...

  4. poj 1654 Area(多边形面积)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17456   Accepted: 4847 Description ...

  5. POJ 3348 Cows 凸包 求面积

    LINK 题意:给出点集,求凸包的面积 思路:主要是求面积的考察,固定一个点顺序枚举两个点叉积求三角形面积和除2即可 /** @Date : 2017-07-19 16:07:11 * @FileNa ...

  6. 【BZOJ1132】【POI2008】Tro 计算几何 叉积求面积

    链接: #include <stdio.h> int main() { puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢"); puts("网 ...

  7. Picture POJ - 1177(扫描线求面积并)

    题意:求矩形并的面积.. 解析: 扫描线第一道题....自下而上扫描的... 如果不懂什么是扫描线戳我 #include <iostream> #include <cstdio> ...

  8. 【改革春风吹满地 HDU - 2036 】【计算几何-----利用叉积计算多边形的面积】

    利用叉积计算多边形的面积 我们都知道计算三角形的面积时可以用两个邻边对应向量积(叉积)的绝对值的一半表示,那么同样,对于多边形,我们可以以多边形上的一个点为源点,作过该点并且过多边形其他点中的某一个的 ...

  9. poj 1654:Area 区域 ---- 叉积(求多边形面积)

    Area   Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19398   Accepted: 5311 利用叉积求多边形面 ...

随机推荐

  1. Python调用MYSQL,将文件名和路径批量入库用法小结

    最近项目需要将大量的压缩文件导入到数据库中,所以开始总结用Python批量处理的办法,本次是首先将这些压缩文件的文件名提取出来,然后导入到数据库中. 由于涉及到路径的读取处理,所以方法有os模块和co ...

  2. 【SSH】——spring的控制反转和依赖注入

    spring是一个轻量级的容器框架,主要是为了使企业的开发变得简单.高效.无论是从大小还是开销来讲,他都可以算是轻量级的,也是非侵入性的. 下图是spring的框架示意图,说到spring,就不得不提 ...

  3. bcc编译

    bcc编译,直接在docker里编,太方便:第一次深切体会到docker的强大: 1)下载bcc源码: 2) 把源码中的Dockerfile.ubuntu重命名为Dockerfile 3)sudo d ...

  4. hdu 3496 Watch The Movie (二维背包)

    Watch The Movie Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)T ...

  5. P4018 Roy&October之取石子

    题目背景 Roy和October两人在玩一个取石子的游戏. 题目描述 游戏规则是这样的:共有n个石子,两人每次都只能取 p^kpk 个(p为质数,k为自然数,且 p^kpk 小于等于当前剩余石子数), ...

  6. 第一个贴上XMT标签的Hadoop程序

    距离老板留给我并行化做属性约简的任务开始到今天,已是一周有余,期间经历过各种呕心沥血,通宵达旦,终于运行出了一个结果.其中在配置过程中,浪费了爷大量的时间,有时回想自己上个周干的事情,会觉得分明的本末 ...

  7. cdh版本的hadoop安装及配置(伪分布式模式) MapReduce配置 yarn配置

    安装hadoop需要jdk依赖,我这里是用jdk8 jdk版本:jdk1.8.0_151 hadoop版本:hadoop-2.5.0-cdh5.3.6 hadoop下载地址:链接:https://pa ...

  8. [Leetcode] The minimum depth of binary tree二叉树的最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  9. clear:both其实是有瑕疵的

    在开发中,从美工MM给你Html代码中,肯定能经常看"<div style="clear:both;"></div>"这样的代码,但是你 ...

  10. 如何抓取开了gzip的网页

    有时候用 file_get_contents() 函数抓取网页会发生乱码现象.有两个原因会导致乱码,一个是编码问题,一个是目标页面开了Gzip. 编码问题好办,把抓取到的内容转下编码即可($conte ...