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

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

代码如下:

#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\n", ok);
}
return 0;
}

UVaLive 7461 Separating Pebbles (暴力)的更多相关文章

  1. UVALive 7461 Separating Pebbles (计算几何)

    Separating Pebbles 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/H Description http://7 ...

  2. UVALive7461 - Separating Pebbles 判断两个凸包相交

    //UVALive7461 - Separating Pebbles 判断两个凸包相交 #include <bits/stdc++.h> using namespace std; #def ...

  3. Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)

    题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...

  4. UVALive 4423 String LD 暴力

    A - String LD Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Stat ...

  5. UVaLive 3401 Colored Cubes (暴力)

    题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...

  6. UVALive 6912 Prime Switch 暴力枚举+贪心

    题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  7. UVALive 6855 Banks (暴力)

    Banks 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/A Description http://7xjob4.com1.z0 ...

  8. UVALive 7077 - Little Zu Chongzhi's Triangles(暴力)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  9. UVaLive 6625 Diagrams & Tableaux (状压DP 或者 DFS暴力)

    题意:给一个的格子图,有 n 行单元格,每行有a[i]个格子,要求往格子中填1~m的数字,要求每个数字大于等于左边的数字,大于上边的数字,问有多少种填充方法. 析:感觉像个DP,但是不会啊...就想暴 ...

随机推荐

  1. BUPT复试专题—密码(2009)

    题目描述   输入 有多组输入,每组: 第一行:由26个小写字母组成的串以空格隔开,如 b a c e u f g h i j k l m n o p q r s t v w x y z d v y ...

  2. 转:一个android开发者独立开发社交app全过程

    http://www.cnblogs.com/linguanh/p/5683069.html

  3. 向C#的选项卡中添加自定义窗体

    一.自定义窗体的搭建 这个比较简单,添加一个WinForm窗体就行了,设置一个名字EditPanel,然后在窗体上画需要的控件. 二.将自定义窗体添加到选项卡 // 新建窗体加入到选项卡中 EditP ...

  4. 生活娱乐 Wifi机器人的制作流程

    思路简单,但是创意无限~~ 动手能力超强 牛人教你做Wifi机器人(图) 一.前言 Wifi机器人(Wifi Robot):其实是一辆能通过互联网,或500米以外的笔记本无线设施来远程控制的遥控汽车. ...

  5. 【转载】一致性哈希算法(consistent hashing)

    一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT)实现算法,设计目标是为了解决因特网中的热点(Hot spot)问题,初衷和CARP十分类似.一致性哈希修正了CARP使用的简 单哈 ...

  6. U盘 文件被隐藏解决办法

    原地址:http://www.deyi.com/thread-351635-1-1.html 方法:运行cmd( 在任意目录都行)单个文件 :attrib c:\"要修改的文件夹名字&quo ...

  7. HDU 1423 Greatest Common Increasing Subsequence(LICS入门,只要求出最长数)

    Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536 ...

  8. QEMU+GDB调试方法

    两年前调试usb/ip开源项目时,就曾用虚拟机远程调试过Windows和Linux系统内核,当时在VMware Workstation上创建两个虚拟机进行调试,也没有记录下如何配置调试,只是大体的还记 ...

  9. 李洪强iOS开发之 - enum与typedef enum的用法

    李洪强iOS开发之 - enum与typedef enum的用法 01 - 定义枚举类型 上面我们就在ViewController.h定义了一个枚举类型,枚举类型的值默认是连续的自然数,例如例子中的T ...

  10. 高仿webqq做的一个webos桌面效果和web聊天工具,桌面效果完好,功能强大

    QQ技术交流群:159995692 /--------   暂时开放的測试       帐号/password:[88888888/1;666666/1]    ---------/ 正如大家所知的E ...