Test instructions: Gives two types of points on the plane, judging whether a line can be drawn to completely separate the two types of points.
Analysis: Use violence to enumerate any two points as a straight line.
The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < cmath> #include <stack> #define FREOPENR freopen ("In.txt", "R", stdin) #define FREOPENW freopen ("OUT.txt", "W", STDOUT) using namespace Std;typedef long Long ll;typedef pair<int, int> p;const int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f;const LL LNF = 0x3f3f3f3f3f3f;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int maxn = 1E3 + 100;const int mod = 1e9 + 7;const int dr[] = {-1, 0, 1, 0};const int dc[] = {0, 1, 0, -1};const char *hex[] = {"0000", " 0001 "," 0010 "," 0011 "," 0100 "," 0101 "," 0110 "," 0111 "," "," 1001 "," 1010 "," 1011 "," 1100 "," 1101 "," 1110 "," 1111 "};int N, m;const int mon[] = {0, 31, 28, 31, 30, 31, 30, [0], +, +, +, 31};const int monn[] = (= {+), H, H, H, +, +,,,,, int, int. b) {return a < b a:b;} inline int Max (int a, int b) {return a > b a:b;} inline ll Min (ll A, ll b) {return a < b a:b;} inline ll Max (ll A, ll b) {return a > b a:b;} inline bool Is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;} struct node{int x, Y, Val; BOOL operator < (const node &p) const{return Val < p.val; }};node a[255];int judge (const node &P1, const node &P2, const node &P3) {return (p1.x-p3.x) * (P2.Y-P3.Y) -(P1.Y-P3.Y) * (p2.x-p3.x);}
BOOL CMP (const node &P, const node &q) {return p.x < q.x | | (p.x = = q.x && p.y < q.y);} BOOL Solve (int s, int t) {int x = 0, y = 0; Vector<node> v; for (int i = 0; i < n; ++i) {if (i = = S | | t = = i) continue; if (!judge (A[s], a[t], A[i])) {v.push_back (a[i]); Continue } if (judge (A[s], a[t], a[i]) > 0 &&!a[i].val) {if (!x) x = 1, y =-1; else if (x < 0) return false; } else if (judge (A[s], a[t], A[i]) < 0 &&!a[i].val) {if (!x) x =-1, y = 1; else if (x > 0) return false; } else if (judge (A[s], a[t], a[i]) > 0 && a[i].val) {if (!y) y = 1, x =-1; else if (Y < 0) return false; } else if (judge (A[s], a[t], A[i]) < 0 && a[i].val) {if (!y) y =-1, x = 1; else if (Y > 0) return false; }} if (!v.size ()) return true; int OK = 0; V.pusH_back (A[s]); V.push_back (A[t]); Sort (V.begin (), V.end (), CMP); int cnt = 0; for (int i = 0; i < v.size (); ++i) {if (V[i].val &&!ok) {ok = 1; } else if (!v[i].val &&!ok) {ok =-1; } else if (v[i].val && OK = =-1) {OK = 1; ++cnt; } else if (!v[i].val && ok = = 1) {OK =-1; ++cnt; } if (CNT > 1) return false; } return true; int main () {int T; Cin >> T; while (t--) {scanf ("%d", &n); for (int i = 0; i < n; ++i) {scanf ("%d%d%d", &a[i].x, &a[i].y, &a[i].val); } bool OK = false; for (int i = 0; i < n; ++i) {for (int j = i+1; j < n; ++j) if (Solve (i, j)) {OK = true; Break } if (OK) break; } printf ("%d\n", OK); } return 0;}
Uvalive 7461 Separating Pebbles (violence)