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. get-post区别

    原文链接:http://www.techweb.com.cn/network/system/2016-10-11/2407736.shtml GET和POST是HTTP请求的两种基本方法,要说它们的区 ...

  2. ubuntu16.04上安装Jenkins,获取登陆密码

    sudo cat /usr/share/tomcat7/.jenkins/secrets/initialAdminPassword

  3. Goroutines和Channels(一)

    Go语言中的并发程序可以用两种手段来实现.本章讲解goroutine和channel,其支持“顺序通信进程”(communicating sequential processes)或被简称为CSP.C ...

  4. Ubuntu14.04(server amd 64)编译安装 ceres-solver

    文档地址:http://www.ceres-solver.org/installation.html git地址:(需要FQ下载) git clone https://ceres-solver.goo ...

  5. Xcode集成POD教程

    http://www.cocoachina.com/ios/20150410/11526.html COCOAPODS的网站上有很多非常好用的资源,这里来说一下如何把POD集成到我们的Xcode项目中 ...

  6. TinyXML用法小结2

    参考:http://www.cnblogs.com/hgwang/p/5833638.html TinyXML用法小结 1.      介绍 Tinyxml的官方网址:http://www.grinn ...

  7. ASP.NET调用dos命令获取交换机流量

    protected void btn_Cisco_Click(object sender, EventArgs e) { try { string ip = txt_ip.Value; string ...

  8. 『cs231n』循环神经网络RNN

    循环神经网络 循环神经网络介绍摘抄自莫凡博士的教程 序列数据 我们想象现在有一组序列数据 data 0,1,2,3. 在当预测 result0 的时候,我们基于的是 data0, 同样在预测其他数据的 ...

  9. zzuli 1875多线DP

    1875: 蛤玮的财宝 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 530  Solved: 116 SubmitStatusWeb Board De ...

  10. HDU-3631 Shortest Path (floyd)

    Description When YY was a boy and LMY was a girl, they trained for NOI (National Olympiad in Informa ...