[Gym - 100517K] Kingdom Division 2 二分
大致题意:
给出一个凸包,以及凸包内的两个点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 二分的更多相关文章
- Hacker Rank: Kingdom Division 不完全报告
原题链接: Kingdom Division 由于树的层次可能很深,所以这里不能使用递归版的DFS.我使用了BFS. BFS确定各结点的父结点和它的孩子数. 用逆拓扑排序确定结点的计算顺序. same ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- 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 ...
- 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 ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(DP+二分)
点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...
- Gym 101257G 24 (概率+二分)
题意: 有一道分值为sa的题,n个人比赛写这道题,按照递减的顺序给出每个人的当前分数,和每个人写不出这道题的概率,让你输出有反超现象出现的期望 思路:由于之前把题目翻译错了导致很久没有相通,后来看了别 ...
- Gym - 101911B Glider(前缀和+二分)
传送门:点我 A plane is flying at a constant height of hh meters above the ground surface. Let's consider ...
- 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 ...
- CF Gym 100187M Heaviside Function(二分)
题意:给你一个函数和一些系数,给你一堆询问,求函数值. 根据s的符号,分成两组讨论,函数值与比x小的系数数量有关,二分输出答案. #include<cstdio> #include< ...
随机推荐
- Bootsrap 直接使用
Bootstrap3 直接使用 <!DOCTYPE html> <html> <head> <title>Bootstrap3</title> ...
- LeetCode-Insertion Sort List[AC源码]
package com.lw.leet5; /** * @ClassName:Solution * @Description: * Insertion Sort List * Sort a linke ...
- Asp.Net MVC +EF CodeFirst+多层程序设计
1.概述 这是一个基于个人博客的一个项目,虽然博客根本没必要做这么复杂的设计.但是公司有需求,所以先自己弄个项目练练手.项目需要满足下列需求 1.层与层之间需要解耦,在后期上线更新维护时不需要覆盖,只 ...
- linux中操作数据库的使用命令记录
1,mysql 查看数据库表编码格式: show create table widget; 修改数据库表编码格式: alter table widget default character set u ...
- JAVA中反射机制四
声明:如需转载请说明地址来源:http://www.cnblogs.com/pony1223 反射四 利用反射获取类的属性 1.通过反射也可以获取到类中的属性,假设我们继续使用Person这个类,然后 ...
- HDU 2191 珍惜现在,感恩生活 (dp)
题目链接 Problem Description 急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都 ...
- NYOJ 133 子序列 (离散化)
题目链接 描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 8 8 1 1,所求子串就是2 8 8 8 1. 输入 第一行输入一个整 ...
- Vmware安装ubuntu详细教程
1.环境准备: (1) 范例系统为WIN10 64位家庭普通版,已正确安装虚拟机VMware Workstation 12 Pro.(2) 下载Ubuntu系统. 2.安装过程: 2.1 VMware ...
- Axure RP 授权码
Axure RP 8.1.0.3372Licensee:KoshyKey:wTADPqxn3KChzJxLmUr5jTTitCgsfRkftQQ1yIG9HmK83MYSm7GPxLREGn+Ii6x ...
- 笔记本自开wifi设置
笔记本自开wifi设置 是这样的有些笔记本他自身就可以放出热点供其他的小伙伴们连接,不用非得去下专门的工具有些笔记本的网卡是自带支持双收发的(这里注意我指的是有些笔记本不是全部) 命令我已经写出来了 ...