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: ...
随机推荐
- mayan 游戏真是毒瘤
如题 真坑呀!!! 可算过了 我率先达到了氧气富有化 先是改变时没有fall.40分 然后是fall函数写慢了 tle 50分 . 上代码 #include<cstdio> #includ ...
- Python基础之字符串(str)常用操作
1.字符串常用的方法 len()返回字符串的长度 ##Python3 >>> print(len('ab12我')) 5 ##Python2 >>> print(l ...
- XML 对xml文件的crud的增加 create操作 增加元素 增加属性
把创建的节点挂到上一节点的最后 找到参考节点,使用insertBefore方法进行插入位置 xml添加属性使用setAttribute方法
- mysql存储问题
为什么标题要起这个名字呢?commen sence指的是那些大家都应该知道的事情,但往往大家又会会略这些东西,或者对这些东西一知半解,今天我总结下自己在mysql中遇到的一些commen sense类 ...
- NPM 学习笔记整理
NPM 学习笔记整理 阅读 550,2017年06月04日 发布,来源:blog.ihoey.com 什么是 NPM npm 之于 Node ,就像 pip 之于 Python , gem 之于 Ru ...
- ssm整合-错误2
1 警告: No mapping found for HTTP request with URI [/management] in DispatcherServlet with name 'dispa ...
- php 删除指定扩展名文件
<?php /** *@param $path文件夹绝对路径 $file_type待删除文件的后缀名 *return void */ function clearn_file($path, $f ...
- python之微信自动发送消息
代码如下: from __future__ import unicode_literals from threading import Timer from wxpy import * import ...
- HyperLedger Fabric ca 1.2 正式环境部署
生成一个根CA(RootCA),在根CA下3个中间CA(IntermediaCA). 1. 运行和配置RootCA服务#cd /opt/gopath/src/github.com/hyperledge ...
- Vsftpd服务 和 TFTP协议
FTP 文件传输协议 (File Transfer Protocol) FTP是一种在互联网中进行文件传输的协议,基于客户端/服务器模式,默认使用20.21号端口,其中端口20(数据端口)用于进行数据 ...