zoukankan      html  css  js  c++  java
  • [ 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 */
  • 相关阅读:
    C++程序设计实验-3
    函数
    C++简单程序设计
    C++程序设计实验-2
    C++程序设计实验-1
    项目总结
    团队测试计划
    第二阶段团队绩效评分
    第二阶段scrum-10
    第二阶段scrum-9
  • 原文地址:https://www.cnblogs.com/general10/p/5789311.html
Copyright © 2011-2022 走看看