HDU 3775 Chain Code ——(Pick定理)
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定理)的更多相关文章
- HDU 3775 Chain Code pick定理
pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b÷2-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积. 思路:http://blog.csdn.net ...
- 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: ...
随机推荐
- xmind的第八天笔记
- LintCode Search a 2D Matrix II
排好序的二维数组, 从上到下从左到右增大, 给出一个数找出此数组里有多少个这个数. 不用两个循环做, 着手于条件(从左下角开始,若相等往右上跳一个,若小于target往右边跳一个,若大于target往 ...
- Java多线程之ConcurrentSkipListMap深入分析(转)
Java多线程之ConcurrentSkipListMap深入分析 一.前言 concurrentHashMap与ConcurrentSkipListMap性能测试 在4线程1.6万数据的条件下, ...
- GCC中文手册
GCC 1 NAME gcc,g++-GNU工程的C和C++编译器(egcs-1.1.2) 总览(SYNOPSIS) gcc[option|filename ]... g++[option|filen ...
- c++ poco库https调用
#include "Poco\File.h"#include "Poco\FileStream.h"#include "Poco\Process.h& ...
- jquery选择器之子元素
HTML代码: :first-child 匹配第一个子元素,每个父元素的第一个子元素 :last-child 匹配最后一个子元素,每个父元素的最后一个子元素 <!DOCTYPE html> ...
- 过滤HTML代码
public static string FilterHtml(string string_include_html) { string[] HtmlRegexArr ={ #region Html ...
- python--ulipad控制台中文输出乱码
ulipad用起来顺手,而不尽人意的地方时,它不能正确输出中文.而且有人指出这和文件的编码没关系,所以将”设置“选项里”缺省文档编码“修改为”utf-8“也无济于事.为了解决这个问题,我在网上搜了搜, ...
- 3、Linux 获取帮助的方法-关机命令-7个系统启动级别
1.获取帮助的方法: (1).命令 -h 或--help (2).man man 命令 --->/user 查看user选项 /选项 ---->n 查看下一项 2.关机命令 (1).sh ...
- 一行代码解释.net事件与委托
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; delegat ...