我D写法
#include <iostream>
using namespace std;
const int N = 1010;
typedef long long ll;
struct node{
ll x, y;
}t1[N], t2[N];
int k1, k2;
int check(int a, int b, int c){
int pre = 0;
bool flag = true;
for(int i = 0; i < k1; i ++ ){
ll sum = (ll)a + b * t1[i].x + c * t1[i].y;
if(sum > 0 && (i == 0 || pre == 1)) pre = 1;
else if(sum < 0 && (i == 0 || pre == -1)) pre = -1;
else{
flag = false;
break;
}
}
if(!flag) return 0;
flag = true;
for(int i = 0; i < k2; i ++ ){
ll sum = (ll)a + b * t2[i].x + c * t2[i].y;
if(pre > 0 && sum < 0) continue;
else if(pre < 0 && sum > 0) continue;
flag = false;
break;
}
if(!flag) return 0;
return 1;
}
int main(){
int n, m; cin >> n >> m;
for(int i = 0; i < n; i ++ ){
int x, y;
char type;
cin >> x >> y >> type;
if(type == 'A') t1[k1 ++ ] = {x, y};
else t2[k2 ++ ] = {x, y};
}
while(m -- ){
int a, b, c; scanf("%d%d%d", &a, &b, &c);
if(check(a, b, c)) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
y总写法
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1010;
int n, m;
struct Point{
ll x, y;
char z;
}q[N];
int get(int a, int b, int c, char z){
int s = 0;
for (int i = 0; i < n; i ++ )
if (q[i].z == z)
if (a + b * q[i].x + c * q[i].y > 0) s |= 1;
else s |= 2;
return s;
}
bool check(int a, int b, int c){
int s1 = get(a, b, c, 'A'), s2 = get(a, b, c, 'B');
if (s1 == 3 || s2 == 3) return false;
if (s1 & s2) return false;
return true;
}
int main(){
cin >> n >> m;
for (int i = 0; i < n; i ++ ) cin >> q[i].x >> q[i].y >> q[i].z;
while (m -- ){
int a, b, c;
cin >> a >> b >> c;
if (check(a, b, c)) puts("Yes");
else puts("No");
}
return 0;
}