HDU 2907
http://acm.hdu.edu.cn/showproblem.php?pid=2907
ans=(凸包顶点数-凸包凹面数量)*q-凸包凹面数量*p
重点在求一个凸包的凹面数量,极角排序过后,当前点在凸包上,下一个点不在凸包上,则凹面数量加一。
这个要求的东西说的十分晦涩,样例不足以解释题目,所以此题难点在理解题目要求,然后就是模板的工作
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std ;
const int INF=0xfffffff ;
struct Point{
int x,y ;
int num ;
} ;
Point p[],s[] ;
int top ;
int direction(Point p1,Point p2,Point p3)
{
return (p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y) ;
}
int dis(Point p1,Point p2)
{
return (p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y) ;
}
int cmp(Point p1,Point p2)//极角排序
{
int temp=direction(p[],p1,p2) ;
if(temp<)return ;
if(temp== && dis(p[],p1)<dis(p[],p2))return ;
return ;
}
void Graham(int n)
{
int pos,minx,miny ;
minx=miny=INF ;
for(int i= ;i<n ;i++)
if(p[i].x<minx || (p[i].x==minx && p[i].y<miny))
{
minx=p[i].x ;
miny=p[i].y ;
pos=i ;
}
swap(p[],p[pos]) ;
sort(p+,p+n,cmp) ;
p[n]=p[] ;
s[]=p[] ;s[]=p[] ;s[]=p[] ;
top= ;
for(int i= ;i<=n ;i++)
{
while(direction(s[top-],s[top],p[i])>= && top>=)top-- ;
s[++top]=p[i] ;
}
}
int flag[] ;
int main()
{
int t ;
scanf("%d",&t) ;
while(t--)
{
int pp,qq,n ;
scanf("%d%d%d",&pp,&qq,&n) ;
for(int i= ;i<n ;i++)
{
scanf("%d%d",&p[i].x,&p[i].y) ;
p[i].num=i ;
}
Graham(n) ;
memset(flag,,sizeof(flag)) ;
int cnt= ;
for(int i= ;i<top ;i++)
flag[s[i].num]= ;
flag[n]=flag[] ;
for(int i= ;i<n ;i++)
if(flag[i] && !flag[i+])
cnt++ ;
int ans=(top-cnt)*qq-cnt*pp ;
if(ans<=)puts("") ;
else printf("%d\n",ans) ;
}
return ;
}
HDU 2907的更多相关文章
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- Codeforces Round #189 (Div. 2) D. Psychos in a Line 单调队列dp
D. Psychos in a Line time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Error: Checksum mismatch.
bogon:bin macname$ brew install go ==> Downloading https://homebrew.bintray.com/bottles-portable- ...
- Python 爬虫-BeautifulSoup
2017-07-26 10:10:11 Beautiful Soup可以解析html 和 xml 格式的文件. Beautiful Soup库是解析.遍历.维护“标签树”的功能库.使用Beautifu ...
- Lua脚本语言入门学习其应用教程
Lua脚本可以很容易的被C/C++代码调用,也可以反过来调用C/C++的函数,这使得Lua在应用程序中可以被广泛应用.不仅仅作为扩展脚本,也可以作为普通的配置文件,代替XML,Ini等文件格式,并且更 ...
- C#实现在应用程序间发送消息的方法示例
本文实例讲述了C#实现在应用程序间发送消息的方法.分享给大家供大家参考,具体如下: 首先建立两个C#应用程序项目. 第一个项目包含一个Windows Form(Form1),在Form1上有一个But ...
- Razor及HtmlHelper学习笔记
Razor 不是编程语言.它是服务器端标记语言. 什么是Razor? Razor 是一种允许您向网页中嵌入基于服务器的代码(Visual Basic 和 C#)的标记语法. 当网页被写入浏览器时,基于 ...
- Python基础--列表、元组
一.什么是列表.元组 序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置类型,但最常见 ...
- POJ-3744 Scout YYF I (矩阵优化概率DP)
题目大意:有n颗地雷分布在一条直线上,有个人的起始位置在1,他每次前进1步的概率为p,前进两步的概率为1-p,问他不碰到地雷的概率. 题目分析:定义状态dp(i)表示到了dp(i)的概率,则状态转移方 ...
- PL/SQL Developer 一段时间后变慢,且导致数据库CPU100%的问题(转)
参考: 一段时间不用plsql developer之后重新使用会变得很慢 plsql developer连接数据库导致服务器cpu升高的案例 1.pl/sql dev 变慢的问题,建议设置如下 2. ...
- Eclipse SVN 合并分支/主干
可以从主干合并到分支,也可以从分支合并到主干,根据需要可以选择合适的选项,如下图: