Codeforces 659D Bicycle Race

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

时间: 2024-08-03 02:58:43

Codeforces 659D Bicycle Race的相关文章

[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

[ 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>

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

CodeForces 48C D - The Race

每个加油的站可以确定一个alpha的上下界,取最大的下界,取最下的上界,看看两者之间的满足条件的下一个加油站是否唯一. 因为可以用分数,所有就没用double了 #include<bits/stdc++.h> using namespace std; typedef long long ll; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } struct Fra { ll p,q; Fra(ll x = 0,ll y = 1):p(x),q(y){ n

CodeForces 592C The Big Race

公倍数之间的情况都是一样的,有循环节. 注意min(a,b)>t的情况和最后一段的处理.C++写可能爆longlong,直接Java搞吧...... import java.io.BufferedInputStream; import java.math.BigInteger; import java.util.Scanner; public class Main { public static BigInteger GCD(BigInteger a,BigInteger b) { if(b.c

CodeForces - 404B(模拟题)

Marathon Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose

Codeforces工具总结

本总结针对Linux用户,由于笔者一直使用Ubuntu系统打Codeforces 打Codeforcecs,想精确能力,打出究极罚时,可以考虑以下套餐 套餐一 vim选手 使用vim + fish + cf tool 套餐二 任意IDE选手 使用任意IDE + cf tool + 任意富文本编辑器(首推vscode) 富文本编辑器用于寻找模板和提交代码 IDE用于手敲代码 套餐三 CLion选手 使用CLion + Jhelper + 任意富文本编辑器 cf tool 使用指南 github地址