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. lintcode-87-删除二叉查找树的节点

    87-删除二叉查找树的节点 给定一棵具有不同节点值的二叉查找树,删除树中与给定值相同的节点.如果树中没有相同值的节点,就不做任何处理.你应该保证处理之后的树仍是二叉查找树. 样例 给出如下二叉查找树: ...

  2. linux tcpdump抓包,wireshark实时解析

    转自: http://www.freebuf.com/articles/wireless/6517.html   由于CentOS7上yum安装的wireshark对CoAP的解析支持不太完善,而我w ...

  3. 【EasyNetQ】- 请求回复

    EasyNetQ还支持请求/响应消息传递模式.这使得实现客户端/服务器应用程序变得容易,客户端向服务器发出请求,然后服务器处理请求并返回响应.与传统的RPC机制不同,EasyNetQ请求/响应操作没有 ...

  4. feof问题

    feof()函数是我们C语言中操作文件常见的函数,也是我们最容易出错的函数 这个函数用来表示文件指针是否已经到了文件末尾的下一个位置.这个函数是通用的 可以用在文本文件和二进制文件 (EOF是文件结束 ...

  5. js+jquery 常用选择器函数

    一.获取当前标签 JS: this,如下: <button onclick="fun(this)"></button> Jquery,如下: $(" ...

  6. [转]网页ContentType详细列表

    本文转自:来老师的专栏   http://blog.csdn.net/sweetsoft/article/details/6512050 不同的ContentType 会影响客户端所看到的效果.默认的 ...

  7. [Java] 各种常用函数

    1.writeInt()和readInt() 这两个函数并不是写入一个整数,读取一个整数.它们实际上是写入4个字节,读取4个字节. writeInt(int i)把i按四个字节,二进制形式写到输出流里 ...

  8. BZOJ4785 [Zjoi2017]树状数组 【二维线段树 + 标记永久化】

    题目链接 BZOJ4785 题解 肝了一个下午QAQ没写过二维线段树还是很难受 首先题目中的树状数组实际维护的是后缀和,这一点凭分析或经验或手模观察可以得出 在\(\mod 2\)意义下,我们实际求出 ...

  9. 洛谷 P4168 [Violet]蒲公英 解题报告

    P4168 [Violet]蒲公英 题目背景 亲爱的哥哥: 你在那个城市里面过得好吗? 我在家里面最近很开心呢.昨天晚上奶奶给我讲了那个叫「绝望」的大坏蛋的故事的说!它把人们的房子和田地搞坏,还有好多 ...

  10. 【NOIP模拟赛】chess 建图+spfa统计方案数

    似乎弗洛伊德和迪杰斯特拉都干不了统计方案数,spfa的话就是不断入队就好. #include <cstdio> #include <cstring> #include < ...