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. 软工实践Beta冲刺(2/7)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...

  2. sc"

    2.11 题目:二叉搜索树中的最近公共祖先 2.12 设计思路 if 树中不存在 u 或 v 错误 结束程序 定义 p 指向根节点 while true do: if p->key大于 u 和 ...

  3. sqlite sql语句关键字GROUP BY的理解

    第一遍看GROUP BY的介绍时,没看懂. SQLite 的 GROUP BY 子句用于与 SELECT 语句一起使用,来对相同的数据进行分组.在 SELECT 语句中,GROUP BY 子句放在 W ...

  4. BZOJ 3668:起床困难综合症(贪心)

    分析:按位贪心即可. program sleep; var a,g:..]of longint; n,i,m,ans,t,len,x,y,v:longint; c:char; s:string; e: ...

  5. BZOJ4476 送礼物

    这道题真是有趣呀. 其实就是一个分数规划问题,用一个二分加log来得去掉分母. 分四种情况讨论 1.lenth > L && num ( max ) > num ( min ...

  6. win7中输入文件夹首字母跳到相应的文件或者文件夹,却在搜索栏出现输入的字母

    组织->文件夹和搜索选项->查看->在视图中选择键入项

  7. POJ 3693 Maximum repetition substring(最多重复次数的子串)

    Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10461   Ac ...

  8. 【题解】CQOI2015选数

    这题做的时候接连想错了好多次……但是回到正轨上之后依然是一个套路题.(不过这题好像有比莫比乌斯反演更好的做法,莫比乌斯反演貌似是某种能过的暴力ヽ(´ー`)┌)不过能过也就行了吧哈哈. 首先我们把数字的 ...

  9. Ubuntu下使用find / -name aaa* 提示“find: 路径必须在表达式之前: XXXX”

    在使用find命令查找文件时,出现了如题所示的错误提示,因为之前都是这样用的,也没出过错,这次语法都是一样的居然不行了,很是纳闷. 后来了解到如下的情况: 如果当前所在目录存在要查找的目标文件时会出现 ...

  10. POJ3349 Snowflake Snow Snowflakes (hash

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 48624   Accep ...