zoukankan      html  css  js  c++  java
  • GYM 101128 J.Saint John Festival(求凸包是否包含点)

    链接:http://codeforces.com/gym/101128

    题意:给定两种点A和B,求有多少个B点,满足存在一个由A组成的三角形,将该点包含在内(包括边界)?

    分析:计算几何模板题。。存在一个A三角形包含某个点的充要条件是这个点在A凸包内,所以求一下A凸包,然后枚举B点,对凸包的每一条边(逆时针方向取),若B点都在边的左侧,则该点在凸包内,否则不在。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 typedef long long ll;
     7 struct Point{
     8     ll x,y;
     9 };
    10 bool Cmp(Point a,Point b){
    11     if(a.x==b.x)return a.y<b.y;
    12     return a.x<b.x;
    13 }
    14 ll Cross(Point &p1,Point &p2,Point &p3){
    15     return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y);
    16 }
    17 int ConvexHll(Point *p,int n,Point *ch){
    18     sort(p,p+n,Cmp);
    19     int m=0;
    20     for(int i=0;i<n;i++){
    21         while(m>1&&Cross(ch[m-2],ch[m-1],p[i])<=0)m--;
    22         ch[m++]=p[i];
    23     }
    24     int k=m;
    25     for(int i=n-2;i>=0;i--){
    26         while(m>k&&Cross(ch[m-2],ch[m-1],p[i])<=0)m--;
    27         ch[m++]=p[i];
    28     }
    29     if(n>1)m--;
    30     return m;
    31 }
    32 Point _La[10005],Sm[50005],La[10005];
    33 int _L,L,S;
    34 bool Is_InCH(Point &s){
    35     for(int i=0;i<L-1;i++){
    36         if(Cross(La[i],La[i+1],s)<0)return false;
    37     }
    38     if(Cross(La[L-1],La[0],s)<0)return false;
    39     return true;
    40 }
    41 int main(){
    42 //    freopen("e:\in.txt","r",stdin);
    43     int cnt=0;
    44     scanf("%d",&_L);
    45     for(int i=0;i<_L;i++)scanf("%d%d",&_La[i].x,&_La[i].y);
    46     scanf("%d",&S);
    47     for(int i=0;i<S;i++)scanf("%d%d",&Sm[i].x,&Sm[i].y);
    48     L=ConvexHll(_La,_L,La);
    49     for(int i=0;i<S;i++){
    50         if(Is_InCH(Sm[i]))cnt++;
    51     }
    52     printf("%d
    ",cnt);
    53     return 0;
    54 }
  • 相关阅读:
    Mysql一套完整练习题
    Ubuntu kylin优麒麟下配置Hive环境
    win10解决无法远程桌面连接问题(参考)
    OSI七层模型的工作协议划分
    20201116-每日一题
    20201115-福州大学-助教-周总结-第9次
    2020年11月学习记录
    20201104-福州大学-助教-周总结-第7次
    2020年10月学习记录
    20201025-福州大学-助教-周总结-第6次
  • 原文地址:https://www.cnblogs.com/7391-KID/p/7630083.html
Copyright © 2011-2022 走看看