[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< ...
随机推荐
- How to ignore SSL certificate errors in Apache HttpClient 4.4
public static CloseableHttpClient acceptsUntrustedCertsHttpClient() throws KeyStoreException, NoSuch ...
- Spring Cloud全家桶主要组件及简要介绍
一.微服务简介 微服务是最近的一两年的时间里是很火的一个概念.感觉不学习一下都快跟不上时代的步伐了,下边做一下简单的总结和介绍. 何为微服务?简而言之,微服务架构风格这种开发方法,是以开发一组小型服务 ...
- 【洛谷P1104】生日
题目描述 cjf君想调查学校OI组每个同学的生日,并按照从大到小的顺序排序.但cjf君最近作业很多,没有时间,所以请你帮她排序. 输入输出格式 输入格式: 有2行,第1行为OI组总人数n:第2行至第n ...
- hash(2018年CSUST省赛选拔赛第一场B题+hash+字典树)
题目链接:http://csustacm.com:4803/problem/1006 题目: 思路:正如题目一样,本题是一个hash,比赛的时候用的字典树,但是不知道为什么一直RE(听学长说要动态开点 ...
- 2017ACM暑期多校联合训练 - Team 2 1001 HDU 6045 Is Derek lying? (模拟)
题目链接 Problem Description Derek and Alfia are good friends.Derek is Chinese,and Alfia is Austrian.Thi ...
- 5.Longest Palindromic Substring---dp
题目链接:https://leetcode.com/problems/longest-palindromic-substring/description/ 题目大意:找出最长回文子字符串(连续). 法 ...
- 设计模式之笔记--享元模式(Flyweight)
享元模式(Flyweight) 定义 享元模式(Flyweight),运用共享技术有效地支持大量细粒度的对象. 类图 描述 Flyweight:抽象享元类,是所有的具体享元类的基类,为子类规定出需要实 ...
- mysql 数据库备份及恢复
1.备份 # 导出数据库:mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -–add-drop-table -uusername -ppassword da ...
- UVA 11624 Fire!(两次BFS+记录最小着火时间)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- Spring Boot Admin Quick Start
Quick Start 1. Spring Boot Admin是干什么的? 用来监控Spring Boot项目,可以通过Spring Boot Admin Client(via Http) 或者 使 ...