• [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积


    问有多少个点在多边形内

    求一遍叉积 小于零计数就好了~

     1 #include<stdio.h>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<math.h>
     5 #include<string.h>
     6 #include<string>
     7 #include<map>
     8 #include<set>
     9 #include<vector>
    10 #include<queue>
    11 #define M(a,b) memset(a,b,sizeof(a))
    12 using namespace std;
    13 typedef long long ll;
    14 struct point{
    15     int x,y;
    16 }pnt[1005];
    17 int solve(point a,point b,point c){
    18     return (b.x-a.x)*(c.y-b.y)-(c.x-b.x)*(b.y-a.y);
    19 }
    20 int main(){
    21     int n;
    22     scanf("%d",&n);
    23     n++;
    24     for(int i=0;i<n;i++)
    25         scanf("%d%d",&pnt[i].x,&pnt[i].y);
    26     int ans=0;
    27     for(int i=2;i<n;i++)
    28         if(solve(pnt[i-2],pnt[i-1],pnt[i])>0) ans++;
    29     printf("%d
    ",ans);
    30     return 0;
    31 }
    32 /*
    33 
    34 6
    35 0 0
    36 0 1
    37 1 1
    38 1 2
    39 2 2
    40 2 0
    41 0 0
    42 
    43 16
    44 1 1
    45 1 5
    46 3 5
    47 3 7
    48 2 7
    49 2 9
    50 6 9
    51 6 7
    52 5 7
    53 5 3
    54 4 3
    55 4 4
    56 3 4
    57 3 2
    58 5 2
    59 5 1
    60 1 1
    61 
    62 */
  • 相关阅读:
    小三学算术
    The Balance
    扫描线
    2019牛客暑期多校训练营(第九场)
    后缀数组
    Manacher
    局部变量和全局变量的区别
    2386:Lake Counting-poj
    简单背包问题(0032)-swust oj
    编程中易犯错误集锦-持续更新。。。。。
  • 原文地址:https://www.cnblogs.com/general10/p/5789311.html
Copyright © 2020-2023  润新知