题目
题目链接: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;
}