Codeforces #284 C. Crazy Town 几何

本文介绍了一种算法,用于计算二维平面上两点间被若干直线分割形成的区域数量。通过判断两点代入每条直线方程后的符号变化,确定两点间直线的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目

题目链接:http://codeforces.com/problemset/problem/499/C

题目来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105944#problem/F

简要题意:一个平面内有若干直线将平面分割成很多区域,问一个点走到另一个点经过多少区域。

题解

可以反向来思考,即两点之间有多少直线。

判断就是去代入方程看两点是否一个为正一个为负。

并不能想到,看了题解才会的,几何实在是不行啊。

代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
// head
int a, b, c;

LL get(LL x, LL y) {
    return a*x + b*y + c;
}

int main() {
    int x1, x2, y1, y2, n;
    scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &a, &b, &c);
        if ((get(x1, y1) ^ get(x2, y2)) < 0) ans++;
    }
    printf("%d\n", ans);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值