题意:给定n个点的坐标4<=n<=1e5 数据范围 ±1e9 整型 已经逆时针排好序
给定两点ab的坐标求n个点的连线中与ab这个线段相交的点对个数
double经常会出现奇怪的问题 这个可以用long long 来做 不会爆精度
首选long long
爆long long 选double 注意恶心的精度问题
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// double EPS=1e-10;
ll add(ll a,ll b){
// if(fabs(a+b)<EPS*(fabs(a)+fabs(b))) return 0;
return a+b;
}
struct P{
ll x,y;
P(){}
P(ll x,ll y):x(x),y(y){}
P operator +(P p){
return P(add(x,p.x),add(y,p.y));
}
P operator -(P p){
return P(add(x,-p.x),add(y,-p.y));
}
P operator *(ll d){
return P(x*d,y*d);
}
ll dot(P p){
return add(x*p.x,y*p.y);
}
ll det(P p){
return add(x*p.y,-y*p.x);
}
};
P ps[2020000];
bool cmp(P a,P b){
return a.x!=b.x?a.x<b.x:a.y<b.y;
}
// vector <P> convex_hull(P*ps,int n){
// sort(ps,ps+n,cmp);
// int k=0;
// vector <P> qs(n<<1);
// for(int i=0;i<n;i++){
// while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
// qs[k++]=ps[i];
// }
// for(int i=n-2,t=k;i>=0;i--){
// while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
// qs[k++]=ps[i];
// }
// qs.resize(k-1);
// return qs;
// }
ll dist(P a,P b){
return (a-b).dot(a-b);
}
ll cal(P a,P b, P c){
return (b-a).det(c-a);
}
int main(){
freopen("kingdom.in","r",stdin);
freopen("kingdom.out","w",stdout);
long long n;
while(cin>>n&&n){
for(int i=0;i<n;i++){
cin>>ps[i].x>>ps[i].y;
// scanf("%lf %lf",&ps[i].x,&ps[i].y);
}
P pt_a,pt_b;
cin>>pt_a.x>>pt_a.y;
cin>>pt_b.x>>pt_b.y;
// scanf("%lf %lf",&pt_a.x,&pt_a.y);
// scanf("%lf %lf",&pt_b.x,&pt_b.y);
long long ans=0;
long long st=1;
long long end=1;
for(int i=0;i<n;i++){
while(cal(ps[i],ps[st],pt_b)>0&&cal(ps[i],ps[st],pt_a)>0){
st=(st+1)%n;
}
if(cal(ps[i],ps[st],pt_b)==0&&cal(ps[i],ps[st],pt_a)==0){
end=st;
}
else{
while(cal(ps[i],ps[st],pt_b)>=0&&cal(ps[i],ps[st],pt_a)>=0){
st=(st+1)%n;
}
while(cal(ps[i],ps[end],pt_a)>0||cal(ps[i],ps[end],pt_b)>0){
end=(end+1)%n;
}
}
long long d=end-st;
if(d<0){
d+=n;
}
ans+=d;
}
cout<<ans/2<<endl;
}
return 0;
}