pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。

思路:http://blog.csdn.net/magicnumber/article/details/6192242

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #define LL long long int
  6.  
  7. using namespace std;
  8.  
  9. const int MAXN = ;
  10. const LL dx[] = { , -, -, -, , , , };
  11. const LL dy[] = { , , , -, -, -, , };
  12.  
  13. struct Point
  14. {
  15. LL x, y;
  16. Point( LL x = , LL y = ):x(x), y(y) { }
  17. };
  18. typedef Point Vector;
  19.  
  20. Vector operator+( Vector A, Vector B ) //向量加
  21. {
  22. return Vector( A.x + B.x, A.y + B.y );
  23. }
  24.  
  25. Vector operator-( Vector A, Vector B ) //向量减
  26. {
  27. return Vector( A.x - B.x, A.y - B.y );
  28. }
  29.  
  30. Vector operator*( Vector A, double p ) //向量数乘
  31. {
  32. return Vector( A.x * p, A.y * p );
  33. }
  34.  
  35. Vector operator/( Vector A, double p ) //向量数除
  36. {
  37. return Vector( A.x / p, A.y / p );
  38. }
  39.  
  40. char str[MAXN];
  41. Point P[MAXN];
  42.  
  43. LL Cross( Vector A, Vector B ) //向量叉积
  44. {
  45. return A.x * B.y - A.y * B.x;
  46. }
  47.  
  48. LL PolygonArea( Point *p, int n ) //多边形有向面积
  49. {
  50. LL area = ;
  51. for ( int i = ; i < n - ; ++i )
  52. area += Cross( p[i] - p[], p[i + ] - p[] );
  53. return area;
  54. }
  55.  
  56. int main()
  57. {
  58. while ( scanf( "%s", str ) == )
  59. {
  60. int n = strlen(str);
  61. Point st = Point(, );
  62. for ( int i = ; i < n; ++i )
  63. {
  64. st.x += dx[ str[i] - '' ];
  65. st.y += dy[ str[i] - '' ];
  66. P[i] = st;
  67. }
  68.  
  69. LL s = PolygonArea( P, n );
  70. if ( s < ) s = -s;
  71.  
  72. printf("%I64d\n", (s + n) / + );
  73. }
  74. return ;
  75. }

HDU 3775 Chain Code pick定理的更多相关文章

  1. HDU 3775 Chain Code ——(Pick定理)

    Pick定理运用在整点围城的面积,有以下公式:S围 = S内(线内部的整点个数)+ S线(线上整点的个数)/2 - 1.在这题上,我们可以用叉乘计算S围,题意要求的答案应该是S内+S线.那么我们进行推 ...

  2. POJ1265——Area(Pick定理+多边形面积)

    Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...

  3. Luogu P2735 电网【真·计算几何/Pick定理】By cellur925

    题目传送门 刷USACO偶然遇到的,可能是人生中第一道正儿八经的计算几何. 题目大意:在平面直角坐标系中给你一个以格点为顶点的三角形,求三角形中的整点个数. 因为必修5和必修2的阴影很快就想到了数学中 ...

  4. POJ 1265 Area (Pick定理 & 多边形面积)

    题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...

  5. 【POJ】2954 Triangle(pick定理)

    http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...

  6. UVa 10088 - Trees on My Island (pick定理)

    样例: 输入:123 16 39 28 49 69 98 96 55 84 43 51 3121000 10002000 10004000 20006000 10008000 30008000 800 ...

  7. Area(Pick定理POJ1256)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5429   Accepted: 2436 Description ...

  8. poj 2954 Triangle(Pick定理)

    链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  9. poj 1265 Area (Pick定理+求面积)

    链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

随机推荐

  1. Spring boot 实现高吞吐量异步处理(适用于高并发场景)

    技术要点 org.springframework.web.context.request.async.DeferredResult<T> 示例如下: 1.   新建Maven项目  asy ...

  2. 怎么让Sublime Text不自动打开最近的文件/项目

    "hot_exit": false,"remember_open_files": false,

  3. 9、SpringBoot+Mybatis整合------动态sql

    开发工具:STS 前言: mybatis框架中最具特色的便是sql语句中的自定义,而动态sql的使用又使整个框架更加灵活. 动态sql中的语法: where标签 if标签 trim标签 set标签 s ...

  4. MySQL时间戳、时间

    MySQL中: now():获取当前时间:例:SELECT now();  // 结果:2018-07-03 13:40:14 unix_timestamp():将时间转换为时间戳:例: SELECT ...

  5. Mac中Mysql开启远程访问(不同于linux直接改配置文件)

    在mac中安装Mysql Workbench 用root用户连上安装的Mysql.  开启远程访问的服务 如下图可以看到是root用户绑定的是localhost  如果不做修改的话,直接访问是访问不了 ...

  6. ubuntu修改IP地址和网关的方法

    一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...

  7. Linux下Mysql5.6 二进制安装

    1.1下载二进制安装包 wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.t ...

  8. Thinkphp 取消Url默认模块的现实

    例子http://www.tp.com/home/index/index 想要现实的效果是:http://www.tp.com/index/index 1是通过配置路由来达到目的 2通过配置首页的入口 ...

  9. python-含参函数

    #!/usr/local/bin/python3 # -*- coding:utf-8 -*- ''' #----------函数位置参数和关键字参数---------- def test(x,y): ...

  10. 希尔排序算法Java实现

    希尔排序(Shell Sort)是插入排序的一种,它是针对直接插入排序算法的改进.该方法又称缩小增量排序,因DL.Shell于1959年提出而得名. 希尔排序实质上是一种分组插入方法.它的基本思想是: ...