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的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. 小米笔记本 air 12.5寸 支持硬盘参数

    M.2接口 2280规格 单面芯片固态硬盘 PCIE协议

  2. Spring boot 遇到了连接mysql的错误

    问题1: Establishing SSL connection without server's identity verification is not recommended. Accordin ...

  3. Centos修改系统语言

    使用man page帮助时,发现居然是中文的,不过想想即便英语再水,也要逼着自己去适应.于是百度找了一下修改系统语言的方法. 首先使用 locale 命令查看当前的系统语言 然后修改时一般有两种方法, ...

  4. 更新自带pip

    想安装docker-compose发现居然找不到pip curl https://bootstrap.pypa.io/get-pip.py | python 直接sudo不行.还是提示权限不够. su ...

  5. Spring AMQP 源码分析 07 - MessageListenerAdapter

    ### 准备 ## 目标 了解 Spring AMQP 如何用 POJO 处理消息 ## 前置知识 <Spring AMQP 源码分析 04 - MessageListener> ## 相 ...

  6. GO 和 KEGG 的区别 | GO KEGG数据库用法 | 基因集功能注释 | 代谢通路富集

    一直都搞不清楚这两者的具体区别. 其实初学者搞不清楚很正常,因为它们的本质是相通的,都是对基因进行归类注释的数据库. 建议初学者自己使用一下这两个数据库,应该很快就能明白其中的区别. (抱歉之前没讲清 ...

  7. memcached set命令的大致处理逻辑笔记

    这次记录状态机的主要逻辑,跟踪set命令的执行流程,暂不涉及到内存申请这一块,下面内容基本都是代码注释 首先还是补充了解下客户连接在发送数据到数据被处理并返回过程中conn的各种状态的表示 enum ...

  8. java通过java.net.URL发送http请求调用接口

    一般在*.html,*.jsp页面中我们通过使用ajax调用接口,这个是我们通常用的.对于这些接口,大都是本公司写的接口供自己调用,所以直接用ajax就可以.但是,如果是多家公司共同开发一个东西,一个 ...

  9. 『Sklearn』数据划分方法

    原理介绍 K折交叉验证: KFold,GroupKFold,StratifiedKFold, 留一法: LeaveOneGroupOut,LeavePGroupsOut,LeaveOneOut,Lea ...

  10. Hadoop生产环境搭建(含HA、Federation)

    Hadoop生产环境搭建 1. 将安装包hadoop-2.x.x.tar.gz存放到某一目录下,并解压. 2. 修改解压后的目录中的文件夹etc/hadoop下的配置文件(若文件不存在,自己创建.) ...