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. 纯CSS实现一个微信logo,需要几个标签?

    博客已迁移至http://lwzhang.github.io. 纯CSS实现一个微信logo并不难,难的是怎样用最少的html标签实现.我一直在想怎样用一个标签就能实现,最后还是没想出来,就只好用两个 ...

  2. preg_match

    $baseUrl = request()->baseUrl(); if (!preg_match('/admin.php/',$baseUrl)) { $this->redirect('/ ...

  3. RabbitMQ入门_04_Exchange & Binding

    如果你比较细心,你会发现 HelloWorld 例子中的 Sender 只申明了一个 hello 队列,然后就开始向默认 Exchange 发送路由键为 hello 的消息.按照之前 AMQP 基本概 ...

  4. Java 常用对象-BigInteger类

    2017-11-02 21:57:09 BigInteger类:不可变的任意精度的整数.所有操作中,都以二进制补码形式表示 BigInteger(如 Java 的基本整数类型).BigInteger ...

  5. ASCII 对照表

    ASCII(American Standard Code for Information Interchange,美国信息互换标准代码,ASCⅡ)是基于拉丁字母的一套电脑编码系统.它主要用于显示现代英 ...

  6. Linux crontab定时执行任务 命令格式与详细例子(转)

    基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...

  7. 20170523xlVBA多条件分类求和一例

    Public Sub NextSeven_CodeFrame() Application.ScreenUpdating = False Application.DisplayAlerts = Fals ...

  8. python-day13--装饰器

    1.开放封闭的原则: 1.对扩展是开放的 为什么要对扩展开放呢? 我们说,任何一个程序,不可能在设计之初就已经想好了所有的功能并且未来不做任何更新和修改.所以我们必须允许代码扩展.添加新功能. 2.对 ...

  9. SSM框架整合(实现从数据库到页面展示)

    SSM框架整合(实现从数据库到页面展示) 首先创建一个spring-web项目,然后需要配置环境dtd文件的引入,环境配置,jar包引入. 首先让我来看一下ssm的基本项目配件.(代码实现) 1.首先 ...

  10. CentOS 7中firewall防火墙详解和配置以及切换为iptables防火墙

    官方文档介绍地址: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Gui ...