[ 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\n",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 */
时间: 2024-08-05 09:27:14

[ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积的相关文章

Codeforces 659D Bicycle Race

Codeforces 659D Bicycle Race Description:自行车每次行走都只有四个方向上,下,左,右:如果内角大于等于270度,自行车就会掉海里. 骑自行车旅行,第一个点为起点坐标,最后一个点还是起点坐标(表示自行车绕了一圈又回来了),问在骑行过程中总共掉海里几次? 呐.拿过来居然不会.果然还是窝太弱了. Solution: 1. 朴素. 叉积:看两个向量夹角,如果夹角小于90度,则直走的话会掉进水里. 1 #include<cstdio> 2 const int ma

[2016-04-01][codeforces][659D][Bicycle Race]

时间:2016-04-01 19:10:24 星期五 题目编号:[2016-04-01][codeforces][659D][Bicycle Race] 题目大意:绕着海岸线行走,每次行走方式为上下左右,最后回到终点,在转弯的地方如果不及时转弯就会掉到水里,问有多少个地方可能掉到水里 分析: 可以发现,在内角为270°的地方才有可能掉到水里,设这样的地方有x个,则内角和 180 * (n - 2) = 270 * x + (n - x) * 90,得到 x = n?42n?42 #include

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

Codeforces Round #346 (Div. 2) (659A,659B,659C,659D(几何叉乘),659E(并查集))

Round House 题目链接: http://codeforces.com/problemset/problem/659/A 解题思路: The answer for the problem is calculated with a formula ((a?-?1?+?b)  n + n)  n + 1. Such solution has complexity O(1). There is also a solution with iterations, modelling every o

Codeforces Round #346 (Div. 2)

前三题水 A #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int n, a, b; std::cin >> n >> a >> b; int bb = b; if (b < 0) bb = -b; while (bb--) { if (b < 0) { a--; } else { a++; } if (a == 0) { a

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

诬柯司戎苡xwkx05na97tu1llqac

http://www.qiushibaike.com/tag/%e7%a3%90%e7%9f%b3%e6%b0%b0%e5%8c%96%e9%92%a0%e5%93%aa%e9%87%8c%e6%9c%89%e5%8d%96%2b%ef%bd%91%ef%bc%92%ef%bc%98%ef%bc%95%ef%bc%98%ef%bc%92%ef%bc%99%ef%bc%91%ef%bc%92%ef%bc%90.http://www.gxxc.gov.cn/Town/TownDetails?id=9