大致题意:

  给出一个凸包,以及凸包内的两个点p1,p2,求有多少条经过凸包顶点的直线能够将凸包分割为两部分,且给出的两点分别属于不同的部分

  

  枚举凸包的顶点,二分求出p1,p2线段左边的最大坐标L以及右边的最小坐标R,则答案为R-L-1的累加和除以2

  注意文件输入,输出

   

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 100100
#define eps 1e-9
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e6+7
#define Vector Point
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
struct Point{
double x,y;
int id;
Point(double x=,double y=):x(x),y(y) {}
bool operator < (const Point &a)const{
if(x==a.x) return y<a.y;
return x<a.x;
}
Point operator - (const Point &a)const{
return Point(x-a.x,y-a.y);
}
Point operator + (const Point &a)const{
return Point(x+a.x,y+a.y);
}
Point operator * (const double &a)const{
return Point(x*a,y*a);
}
Point operator / (const double &a)const{
return Point(x/a,y/a);
}
void read(){
scanf("%lf%lf",&x,&y);
}
void out(){
cout<<"debug: "<<x<<" "<<y<<endl;
}
bool operator == (const Point &a)const{
return dcmp(x-a.x)== && dcmp(y-a.y)==;
}
};
double Dot(Vector a,Vector b) {
return a.x*b.x+a.y*b.y;
}
double dis(Vector a) {
return sqrt(Dot(a,a));
}
double Cross(Point a,Point b){
return a.x*b.y-a.y*b.x;
}
int n;
Point p[];
int ls,rs;
int chk1(Point p1,Point p2,int pos){
int l=pos+,r=pos+n-;
while(l<r){
int mid=l+r>>;
if(dcmp(Cross(p[mid]-p[pos],p1-p[pos]))<= && dcmp(Cross(p[mid]-p[pos],p2-p[pos])<=)) r=mid;
else l=mid+;
}
return l;
}
int chk2(Point p1,Point p2,int pos){
int l=pos+,r=pos-+n;
while(l<r){
int mid=l+r+>>;
if(dcmp(Cross(p[mid]-p[pos],p1-p[pos]))>= && dcmp(Cross(p[mid]-p[pos],p2-p[pos]))>=) l=mid;
else r=mid-;
}
return l;
}
Point p1,p2;
void solve(){
For(i,,n) p[i].read();
p1.read();p2.read();
ll ans=;
For(i,,n) p[i+n]=p[i];
For(i,,n){
ls=chk1(p1,p2,i);
rs=chk2(p1,p2,i);
if(ls!=rs)ans+=abs(ls-rs)-;
}
cout<<ans/<<endl;
}
int main(){
// fre("in.txt","r",stdin);
freopen("kingdom.in","r",stdin);
freopen("kingdom.out","w",stdout);
int t=;
while(~scanf("%d",&n) &&n) solve();
return ;
}

[Gym - 100517K] Kingdom Division 2 二分的更多相关文章

  1. Hacker Rank: Kingdom Division 不完全报告

    原题链接: Kingdom Division 由于树的层次可能很深,所以这里不能使用递归版的DFS.我使用了BFS. BFS确定各结点的父结点和它的孩子数. 用逆拓扑排序确定结点的计算顺序. same ...

  2. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  3. hdu 1025:Constructing Roads In JGShining's Kingdom(DP + 二分优化)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  4. HDU 1025:Constructing Roads In JGShining's Kingdom(LIS+二分优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=1025 Constructing Roads In JGShining's Kingdom Problem Des ...

  5. HDU 1025 Constructing Roads In JGShining's Kingdom(DP+二分)

    点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...

  6. Gym 101257G 24 (概率+二分)

    题意: 有一道分值为sa的题,n个人比赛写这道题,按照递减的顺序给出每个人的当前分数,和每个人写不出这道题的概率,让你输出有反超现象出现的期望 思路:由于之前把题目翻译错了导致很久没有相通,后来看了别 ...

  7. Gym - 101911B Glider(前缀和+二分)

    传送门:点我 A plane is flying at a constant height of hh meters above the ground surface. Let's consider ...

  8. codeforce Gym 100500F Door Lock (二分)

    根据题意略推一下,其实就是问你满足(a*(a+1))/2 < m <= ((a+1)*a(a+2))/2的a和m-(a*(a+1))/2 -1是多少. 二分求解就行了 #include&l ...

  9. CF Gym 100187M Heaviside Function(二分)

    题意:给你一个函数和一些系数,给你一堆询问,求函数值. 根据s的符号,分成两组讨论,函数值与比x小的系数数量有关,二分输出答案. #include<cstdio> #include< ...

随机推荐

  1. php 傻瓜式代码计算两个时间间隔

    $stamp = (strtotime($_POST['start'])-strtotime($_POST['end'])); $s = $stamp%60; //秒 $m_stamp= ($stam ...

  2. 基础知识:BT1120

    今天谈点我所理解的BT1120协议. BT1120是高清晰度电视 (HDTV) 演播室信号数字接口,首先说一下接口标准里面的概念,然后谈谈自己的理解,写这个文章的目的就是解释给自己听的,所以都是一些白 ...

  3. 解决VSCode终端中文乱码问题

    VSCode终端其实调用的是cmd.exe,所以当这里出现中文乱码的时候要解决的是cmd的编码设置问题. 可以通过chcp命令查看cmd的编码设置,GBK2312的代码页编号是936,然后改成utf- ...

  4. Codechef Observing the Tree

    Home » Practice(Hard) » Observing the Tree   https://www.codechef.com/problems/QUERY Observing the T ...

  5. Linux两台服务器上互传文件

    主服务器:192.168.100.30: 文件所在服务器:192.168.100.31: 1. 在主服务上拷贝文件: #scp root@192.168.100.31:/home/a.txt /hom ...

  6. linux系统df和du命令的区别

    发现一台用户的电脑,df检查出来的/磁盘空间占用了16G,比用du查看得到的磁盘空间大的多,du查看/下所有程序目录加起来还不到5G.这是什么原因呢? 即便是有隐藏文件,查了也很小啊.   因为df和 ...

  7. JS DOM之表格操作

    一个能给添加行的表格 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...

  8. C# 遍历枚举

    C#中,如何获取(遍历)枚举中所有的值: public enum Suits { Spades, Hearts, Clubs, Diamonds, NumSuits } private static ...

  9. 20155335俞昆《Java程序设计》第五周总结

    #  20155335    <Java程序设计>第五周学习总结 ##  教材学习内容总结 ##  教材学习中的问题和解决过程 对于异常处理,程序中总有意想不到的状况所引发的的错误,Jav ...

  10. MySql 复制表命令

    1.只复制表结构到新表 CREATE TABLE 新表 SELECT * FROM 旧表 WHERE 1=2; 或 CREATE TABLE 新表 LIKE 旧表 ; 注意上面两种方式,前一种方式是不 ...