码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 659D Bicycle Race

时间:2016-08-06 18:49:33      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

Codeforces 659D Bicycle Race

Description:自行车每次行走都只有四个方向上,下,左,右;如果内角大于等于270度,自行车就会掉海里。

骑自行车旅行,第一个点为起点坐标,最后一个点还是起点坐标(表示自行车绕了一圈又回来了),问在骑行过程中总共掉海里几次?

呐。拿过来居然不会。果然还是窝太弱了。

Solution:

1. 朴素。

叉积:看两个向量夹角,如果夹角小于90度,则直走的话会掉进水里。

技术分享
 1 #include<cstdio>
 2 const int maxn = 1000 +5;
 3 int x[maxn], y[maxn];
 4 #define sa(m) scanf("%d",&m)
 5 int judge(int x1, int y1, int x2, int y2, int x3, int y3)
 6 {
 7     return (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2) > 0;
 8 
 9 }
10 int main (void)
11 {
12     int n;sa(n);
13     int a, b;
14     for(int i = 0; i <= n; i++){
15         sa(x[i]);sa(y[i]);
16     }
17     int res = 0;
18     for(int i = 1; i < n; i++){
19         res += judge(x[i - 1], y[i - 1], x[i], y[i], x[i + 1], y[i + 1]);
20     }
21     printf("%d\n", res);
22     return 0;
23 }
代码不是我写的

2. 数学。呐。这个比较快。代码也简单。

减去竖直水平的四条边,剩下的每两条边的交点就是答案。

因为是直角拐弯,所以内角要么是90度,要么是270度,设270的角的个数为x,则可得方程180 * (n - 2) = 270 * x + (n - x) * 90; 化简得:x = (n - 4) / 2;

渣代码:

技术分享
 1 #include<stdio.h>
 2 #include <iostream>
 3 using namespace std;
 4 int n, a, b;
 5 int main()
 6 {
 7     scanf("%d", &n);
 8     printf("%d\n", (n - 4)/2);
 9     return 0;
10 }
渣代码

--------------------------------

QAQAQAQ马上就要8.11了QAQQAQ

我居然到现在还没写过也根本不会树剖QAQ

耻辱QAQ

Codeforces 659D Bicycle Race

标签:

原文地址:http://www.cnblogs.com/shadyqwq-juruo/p/5744506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!