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. (转载)MYSQL千万级数据量的优化方法积累

    转载自:http://blog.sina.com.cn/s/blog_85ead02a0101csci.html MYSQL千万级数据量的优化方法积累 1.分库分表 很明显,一个主表(也就是很重要的表 ...

  2. Java 无法初始化Connection的问题

    通过断点调试捕获错误消息:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time ...

  3. Java课程设计--学生成绩管理系统

    一.团队名称: 团队成员 林艺薇 201721123032 网络1712 黄毓颖 201721123033 网络1712 唐川 201721123034 网络1712 梁才玉 201721123038 ...

  4. Vue2.0 新手完全填坑攻略——从环境搭建到发布(转载)

    强力推荐,详情请点击此链接http://www.jianshu.com/p/5ba253651c3b

  5. JS实现双击编辑可修改

    需求描述:在一段文字处双击可以进行修改,也就是双击后创建输入框,输入内容,在输入框失去焦点后将输入的内容再以文字的形式显示出来,以下是html代码: 1 <fieldset> 2 < ...

  6. springMVC笔记一

    第一章 回顾JavaWeb中的MVC设计模式 1)MVC这种设计模式,不光运用于Web领域,而且也能用于非Web领域 2)今天说的MVC特指一种表现层设计模式,不限于Java语言 第二章 回顾stru ...

  7. MongoDB 存储日志数据

    MongoDB 存储日志数据 https://www.cnblogs.com/nongchaoer/archive/2017/01/11/6274242.html 线上运行的服务会产生大量的运行及访问 ...

  8. 【ZJ选讲·画山】

    给出一张纸(N × M),你要在上面画山,但不能画出界(N,M<=100) Like this: 起点为(0,0),终点为(N,0) 给出w种线段画法(x,y),表示用了这种画法后,笔迹末 ...

  9. 假的kd-tree小结

    至今还不是很体会kd-tree这种东西,只不过体会了一种解决某些枚举问题的方法,就是当我们有一群元素,我们要到一个答案,答案在这些元素中的某个或某几个中,我们就会枚举他们,然而我们发现这样做十分低效, ...

  10. 【BZOJ 1492】 [NOI2007]货币兑换Cash 斜率优化DP

    先说一下斜率优化:这是一种经典的dp优化,是OI中利用数形结合的思想解决问题的典范,通常用于优化dp,有时候其他的一些决策优化也会用到,看待他的角度一般有两种,但均将决策看为二维坐标系上的点,并转化为 ...