zoukankan      html  css  js  c++  java
  • UVaLive 7461 Separating Pebbles (暴力)

    题意:给出平面上的两类点,判断是否能画一条直线将两类点完全分割开来.

    析:用暴力去枚举任意两点当作直线即可。

    代码如下:

    #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", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, 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 ", ok); } return 0; }
  • 相关阅读:
    系统相关的信息模块: import sys
    Mysql 解决emoji表情处理问题
    Servlet 个人理解
    Java BufferImage 获取像素矩阵 或 数组
    SVN 出现 R6034 错误 Python导致异常
    Mycat 入门
    Mycat 入门
    Nginx 架构
    Nginx 架构 性能优化
    Nginx 架构 性能优化
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5877117.html
Copyright © 2011-2022 走看看