HDU 3775 Chain Code pick定理
pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。
思路:http://blog.csdn.net/magicnumber/article/details/6192242
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <algorithm>
- #define LL long long int
- using namespace std;
- const int MAXN = ;
- const LL dx[] = { , -, -, -, , , , };
- const LL dy[] = { , , , -, -, -, , };
- struct Point
- {
- LL x, y;
- Point( LL x = , LL y = ):x(x), y(y) { }
- };
- typedef Point Vector;
- Vector operator+( Vector A, Vector B ) //向量加
- {
- return Vector( A.x + B.x, A.y + B.y );
- }
- Vector operator-( Vector A, Vector B ) //向量减
- {
- return Vector( A.x - B.x, A.y - B.y );
- }
- Vector operator*( Vector A, double p ) //向量数乘
- {
- return Vector( A.x * p, A.y * p );
- }
- Vector operator/( Vector A, double p ) //向量数除
- {
- return Vector( A.x / p, A.y / p );
- }
- char str[MAXN];
- Point P[MAXN];
- LL Cross( Vector A, Vector B ) //向量叉积
- {
- return A.x * B.y - A.y * B.x;
- }
- LL PolygonArea( Point *p, int n ) //多边形有向面积
- {
- LL area = ;
- for ( int i = ; i < n - ; ++i )
- area += Cross( p[i] - p[], p[i + ] - p[] );
- return area;
- }
- int main()
- {
- while ( scanf( "%s", str ) == )
- {
- int n = strlen(str);
- Point st = Point(, );
- for ( int i = ; i < n; ++i )
- {
- st.x += dx[ str[i] - '' ];
- st.y += dy[ str[i] - '' ];
- P[i] = st;
- }
- LL s = PolygonArea( P, n );
- if ( s < ) s = -s;
- printf("%I64d\n", (s + n) / + );
- }
- return ;
- }
HDU 3775 Chain Code pick定理的更多相关文章
- HDU 3775 Chain Code ——(Pick定理)
Pick定理运用在整点围城的面积,有以下公式:S围 = S内(线内部的整点个数)+ S线(线上整点的个数)/2 - 1.在这题上,我们可以用叉乘计算S围,题意要求的答案应该是S内+S线.那么我们进行推 ...
- POJ1265——Area(Pick定理+多边形面积)
Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...
- Luogu P2735 电网【真·计算几何/Pick定理】By cellur925
题目传送门 刷USACO偶然遇到的,可能是人生中第一道正儿八经的计算几何. 题目大意:在平面直角坐标系中给你一个以格点为顶点的三角形,求三角形中的整点个数. 因为必修5和必修2的阴影很快就想到了数学中 ...
- POJ 1265 Area (Pick定理 & 多边形面积)
题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...
- 【POJ】2954 Triangle(pick定理)
http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...
- 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 ...
- Area(Pick定理POJ1256)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5429 Accepted: 2436 Description ...
- poj 2954 Triangle(Pick定理)
链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- poj 1265 Area (Pick定理+求面积)
链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
随机推荐
- Spring boot 实现高吞吐量异步处理(适用于高并发场景)
技术要点 org.springframework.web.context.request.async.DeferredResult<T> 示例如下: 1. 新建Maven项目 asy ...
- 怎么让Sublime Text不自动打开最近的文件/项目
"hot_exit": false,"remember_open_files": false,
- 9、SpringBoot+Mybatis整合------动态sql
开发工具:STS 前言: mybatis框架中最具特色的便是sql语句中的自定义,而动态sql的使用又使整个框架更加灵活. 动态sql中的语法: where标签 if标签 trim标签 set标签 s ...
- MySQL时间戳、时间
MySQL中: now():获取当前时间:例:SELECT now(); // 结果:2018-07-03 13:40:14 unix_timestamp():将时间转换为时间戳:例: SELECT ...
- Mac中Mysql开启远程访问(不同于linux直接改配置文件)
在mac中安装Mysql Workbench 用root用户连上安装的Mysql. 开启远程访问的服务 如下图可以看到是root用户绑定的是localhost 如果不做修改的话,直接访问是访问不了 ...
- ubuntu修改IP地址和网关的方法
一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...
- 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 ...
- Thinkphp 取消Url默认模块的现实
例子http://www.tp.com/home/index/index 想要现实的效果是:http://www.tp.com/index/index 1是通过配置路由来达到目的 2通过配置首页的入口 ...
- python-含参函数
#!/usr/local/bin/python3 # -*- coding:utf-8 -*- ''' #----------函数位置参数和关键字参数---------- def test(x,y): ...
- 希尔排序算法Java实现
希尔排序(Shell Sort)是插入排序的一种,它是针对直接插入排序算法的改进.该方法又称缩小增量排序,因DL.Shell于1959年提出而得名. 希尔排序实质上是一种分组插入方法.它的基本思想是: ...