Pick定理运用在整点围城的面积,有以下公式:S围 = S内(线内部的整点个数)+ S线(线上整点的个数)/2 - 1。在这题上,我们可以用叉乘计算S围,题意要求的答案应该是S内+S线。那么我们进行推导以后得到ans=S内+S线=(S线+S围)/2+1-->另外,S线即是字符串的长度,那么本题得以解决。

  代码如下:

 #include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll;
const int N = + ; char s[N];
int dx[] = {,-,-,-,,,,};
int dy[] = {,,,-,-,-,,}; int main()
{
while(scanf("%s",s+) == )
{
ll all = ;
ll x = , y = ;
for(int i=;s[i];i++)
{
int val = s[i] - '';
ll xx = x + dx[val];
ll yy = y + dy[val];
all += x * yy - xx * y;
x = xx, y = yy;
}
all = std::abs(all);
printf("%I64d\n",(all+strlen(s+))/ + );
}
return ;
}

HDU 3775 Chain Code ——(Pick定理)的更多相关文章

  1. HDU 3775 Chain Code pick定理

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

  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. java web项目中 获取resource路径下的文件路径

    public GetResource{ String path = GetResource.class.getClassLoader().getResource("xx/xx.txt&quo ...

  2. ueditor在使用requirejs时,报ZeroClipboard undefined错误

    再网上找到了 http://blog.csdn.net/xundh/article/details/44536665       这样一篇文章, 其中原因说的很明白了 是因为在有requirejs时, ...

  3. java Map迭代

    //先入先出 public class Test { public static void main(String[] args) { LinkedHashMap<String,Object&g ...

  4. JSBinding / Home

    Description JSBinding is a tool enabling you to run actual javascript in Unity3D. It contains Mozill ...

  5. Mac下Nginx环境配置

    环境信息: Mac OS X 10.11.1 Homebrew  0.9.5 正文 一.安装 Nginx 终端执行: brew search nginx brew install nginx 当前版本 ...

  6. SQL语句统计每天、每月、每年的 数据

    SQL语句统计每天.每月.每年的数据 1.每年select year(ordertime) 年,sum(Total) 销售合计from 订单表group by year(ordertime) 2.每月 ...

  7. LeetCode "Binary Tree Level Order Traversal II" using DFS

    BFS solution is intuitive - here I will show a DFS based solution: /** * Definition for a binary tre ...

  8. IOS开发中的几种设计模式介绍

    ios开发学习中,经常弄不清楚ios的开发模式,今天我们就来进行简单的总结和探讨~ (一)代理模式 应用场景:当一个类的某些功能需要由别的类来实现,但是又不确定具体会是哪个类实现. 优势:解耦合 敏捷 ...

  9. 详细安装ss的过程(vultr)

    #更新程序yum update -y #安装setuptoolsyum install -y python-setuptools #安装pipeasy_install pip #安装shadowsoc ...

  10. sublime plugin emmet toolkit

    [简写规则]1. E 代表HTML标签.2. E#id 代表id属性.3. E.class 代表class属性.4. E[attr=foo] 代表某一个特定属性.5. E{foo} 代表标签包含的内容 ...