Codeforces Round #284 (Div. 2) C题(计算几何)解题报告

题目地址

简要题意:

  给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A、B、C,这些直线作为街道,求从一点走到另一点需要跨越的街道数。(两点都不在街道上)

思路分析:

  从一点到另一点必须要跨的街道等价于两点一点在这条直线一侧,另一条在另一侧。只需要将两点坐标带进去,一正一负即可。将这些直线依次检验,统计总和。

  

 1 #include<stdio.h>
 2 #include<bits/stdc++.h>
 3 #include <iostream>
 4 using namespace std;
 5 typedef long long ll;
 6 int main()
 7 {
 8     ll x1,x2,y1,y2,n,a,b,c,s,q,ans=0;
 9     scanf("%I64d%I64d",&x1,&y1);
10     scanf("%I64d%I64d",&x2,&y2);
11     scanf("%I64d",&n);
12     while(n--)
13     {
14         scanf("%I64d%I64d%I64d",&a,&b,&c);
15         s=a*x1+b*y1+c;
16         q=a*x2+b*y2+c;
17         if((s>0&&q<0)||(s<0&&q>0))
18             ans++;
19     }
20     printf("%I64d\n",ans);
21     return 0;
22 }
时间: 2024-12-20 15:47:21

Codeforces Round #284 (Div. 2) C题(计算几何)解题报告的相关文章

Codeforces Round #305 (Div. 1) A.B.C 解题报告

A. Mike and Frog 枚举. 先是找循环,然后很容易得出一个两元一次方程,然后可以发现解也是有循环节的,所以最小的那个肯定出现在一定范围内,否则就后面也不可能出现.假设两个变量为x,y,系数分别为z1,z2.很显然,两者的最小公倍数便是一个周期,所以如果枚举x的话,只需要枚举到z2就可以了. 细节比较多..错了好多次..比赛中也跪了.. 代码如下: #include <iostream> #include <string.h> #include <math.h&g

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #243 (Div. 1) A题

http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱! 直接暴力求出矩阵数值,然后枚举每一个[I,J];再O[N]判断,分配好在[I,J]区间的数和之内的数,再排序下SOLO了 CODE:#include <cstdio> #include <cstring>#include <queue>#include <vect

Codeforces Round #284 (Div. 2) b

/**  * @brief Codeforces Round #284 (Div. 2) b  * @file b.cpp  * @author mianma  * @created 2014/12/26 11:51  * @edited  2014/12/18 11:51  * @type brute  * @note  */ #include <fstream> #include <iostream> #include <string> #include <c

Codeforces Round #634 (Div. 3) 补题

A. Candies and Two Sisters 签到题,直接输出即可 代码 #include<bits/stdc++.h> #define INF 0x3f3f3f3f typedef long long ll; using namespace std; inline void read(int &p) { p=0;int flag=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();} w

Codeforces Round #396 (Div. 2) D题Mahmoud and a Dictionary(并查集)解题报告

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discov

Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何

题面 题意:给你2个点A和B,和n条直线(ax+by+c=0),给n个a,b,c,求A到B至少跨过多少条直线 题解:对于每条直线,看2个点是否在他同侧,异侧答案就+1 1 #include<bits/stdc++.h> 2 using namespace std; 3 double x1,x2,y11,y2,a,b,c,t1,t2; 4 int n,ans; 5 int main() 6 { 7 cin>>x1>>y11; 8 cin>>x2>>

[Codeforces Round #284 (Div. 1) B]Name That Tune(概率Dp)

Description It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the so

Codeforces Round #374 (div.2)遗憾题合集

C.Journey 读错题目了...不是无向图,结果建错图了(喵第4样例是变成无向就会有环的那种图) 并且这题因为要求路径点尽可能多 其实可以规约为限定路径长的拓扑排序,不一定要用最短路做 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm>