题目链接:

  http://poj.org/problem?id=1654

题目描述:

Area

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

题目大意:

  一个人会从原点出发,走一圈回到原点,给你路径,求围成面积的大小

思路:

  坑巨多……

  首先路径不需要全部记录,读一个面积加上一部分叉乘即可

  于是需要记录上一个点的坐标

  然后面积只有可能是整数或整数加二分之一

  所以用long long记录二倍面积,加快速度

  int会爆 ……要用long long

  不能用%g输出……手动判断……

  手写abs……防止CE

  卒_(:з」∠)__

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4
 5 const double EPS = 1e-10;
 6 const int N = 24;
 7
 8 typedef long long LL;
 9
10 int a[10] = { 0,-1,0,1,-1,0,1,-1,0,1 };    //记录每种操作走的方向
11 int b[10] = { 0,-1,-1,-1,0,0,0,1,1,1 };
12
13 inline LL ABS(LL n) { return n >= 0 ? n : -n; }    //手动abs
14
15 int main() {
16     int q;
17     char tmp[2];
18     scanf("%d", &q);
19     while (q--) {
20         LL x = 0, y = 0, area = 0, px = 0, py = 0;
21         int op;
22         while (1) {
23             scanf("%1s", tmp);
24             if (tmp[0] == '5')break;    //5终止
25             op = tmp[0] - '0';
26             x += a[op], y += b[op];
27             area += px*y - py*x;    //叉乘
28             px = x, py = y;            //更新上一个坐标
29         }
30         LL ans = ABS(area);
31         if (ans % 2 == 0)printf("%lld\n", ans / 2);
32         else printf("%lld.5\n", ans / 2);
33     }
34 }

转载于:https://www.cnblogs.com/hyp1231/p/6984277.html

POJ1654 Area(多边形面积)相关推荐

  1. poj 1654 Area 多边形面积

    /* poj 1654 Area 多边形面积题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> # ...

  2. pku 2954 Triangle pku 1265 Area Pick定理的应用 + 叉积求多边形面积

    Pick定理证明:http://translate.google.com/translate?u=http://episte.math.ntu.edu.tw/articles/sm/sm_25_10_ ...

  3. hdu2036(多边形面积)

    Description " 改革春风吹满地,  不会AC没关系;  实在不行回老家,  还有一亩三分地.  谢谢!(乐队奏乐)" 话说部分学生心态极好,每天就知道游戏,这次考试如此 ...

  4. python计算多边形面积_Python求凸包及多边形面积教程

    一般有两种算法来计算平面上给定n个点的凸包:Graham扫描法(Graham's scan),时间复杂度为O(nlgn):Jarvis步进法(Jarvis march),时间复杂度为O(nh),其中h ...

  5. HDU2036 改革春风吹满地【多边形面积】

    改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  6. 使用行列式公式求多边形面积

    namespace SKJZ {namespace lib{public struct Point { public float x, y;}public class Polygon{/// < ...

  7. python计算多边形的面积并保留两位小数_Python计算任意多边形面积算法

    多边形面积求解的方法很多,其中比较多见的就是增加一个点P,然后分别连接多边形各个定点与P点,然后计算每个三角形的符号面积(面积有正负之分),求和就可以计算出面积. 鉴于上面的方法,我们也可以用另外一种 ...

  8. 通过坐标点位,计算多边形面积

    多边形面积 本文使用三角形面积累计法计算多边形面积,就是将多边形按照一个顶点,分割成多个三角形,计算三角形的面积,累加,得到多边形的面积. 当然,这个算法也有一些缺点,当这个多边形比较奇怪的时候,不能 ...

  9. c语言给坐标求多边形面积,多边形的面积问题

    多边形的面积问题 设构成多边形的坐标串为(xi,yi)(i=1,2,--,n),求此多边形面积A. #include #define N 10 float Area(float (*x)[2],int ...

  10. vue+d3.js计算任意多边形面积

    效果图 代码 <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF ...

最新文章

  1. 2020年SWPUACM团队新生第四次周赛(题解)
  2. SSH错误:packet_write_wait: Connection to 10.57.19.250 port 22: Broken pipe
  3. CentOS 7 解决丢失 nginx.pid 1
  4. 台式计算机计量单位,计算机的计量单位以及常见的数据类型
  5. 有了螃蟹让心情好一点
  6. [ZJOI2014] 星系调查(树上差分 + 数学推式子)
  7. 初识Python-1
  8. 1.5 编程基础之循环控制 09 奇数求和
  9. Storm入门(三)HelloWorld示例
  10. 垃圾回收算法与实现系列-GC 标记-清除算法
  11. 解决easyExcel和poi版本冲突问题
  12. 攻克难题最忌讳的就是投机取巧自作聪明
  13. 虚拟网络VDC与VPC
  14. 黑马博客——详细步骤(三)项目功能的实现之新增用户
  15. 数学建模——主成分分析及spss软件操作
  16. 计算机组成原理中原码一位乘法
  17. 信息搜集方法总结与思路整合
  18. java.lang.UnsupportedOperationException\r\n\tat java.sql.Date.toInstant(Date.java:304)
  19. java开发季度绩效自评,季度绩效考核英文自我评价
  20. 排查oracle数据库服务是否启动

热门文章

  1. android seekbar 源码,Android SeekBar调节音量
  2. linux c 语言 errno 我个头,Linux错误代码:errno.h与返回值 -EINVAL
  3. 安装配置mac版_全面战争三国 Mac版Mod安装指南
  4. 计算机课程中lnA怎么打,《计算机基础》考试模拟题(含答案)
  5. java 值 继承_java中继承的数值传递引用
  6. latex 公式编号_放弃mathtype,word也可以轻松输入公式
  7. linux三并发进程,linux下用进度条显示三个进程的并发
  8. layui checkbox加th;全选 反选
  9. cannot set up a python sdk 3.8_anaconda+pycharm环境下创建新的虚拟环境报错Cannot set up a py...
  10. 小米蓝牙左右互联_小米真无线蓝牙耳机Air2评测:支持弹窗动画,半入耳设计全面升级...