一、问题描述



二、解答
方法一:分类型遍历所有点
#include<iostream>
using namespace std;
char type[10000000] = { NULL };
int x[10000000] = { 0 };
int y[10000000] = { 0 };
int main()
{
int m, n;
cin >> n >> m;
int o[20] = { 0 };
int p[20] = { 0 };
int q[20] = { 0 };
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i] >> type[i];
}
for (int j = 0; j < m; j++)
{
cin >> o[j] >> p[j] >> q[j];
}
for (int j = 0; j < m; j++)
{
int bigA = 0;
int smallA = 0;
int bigB = 0;
int smallB = 0;
for (int i = 0; i < n; i++)
{
if (type[i] == 'A')
{
int proA = o[j] + p[j] * x[i] + q[j] * y[i];
if(proA>0)
{
bigA++;
}
else if (proA < 0)
{
smallA++;
}
}
else if (type[i] == 'B')
{
int proB = o[j] + p[j] * x[i] + q[j] * y[i];
if (proB > 0)
{
bigB++;
}
else if (proB < 0)
{
smallB++;
}
}
}
if ((smallA==0&&bigA>0&&smallB>0=0)|| (smallA> 0 &= 0 && smallB == 0 && bigB > 0))
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
return 0;
}
方法二:创建结构体
#include<iostream>
using namespace std;
struct Point {
int x;
int y;
char type;
};
struct Line {
int o1;
int o2;
int o3;
};
int main()
{
int m, n;
cin >> n >> m;
struct Point *p;
p = new struct Point[n];
struct Line *l;
l = new struct Line[m];
for (int i = 0; i < n; i++)
{
cin >> p[i].x >> p[i].y >> p[i].type;
}
for (int j = 0; j < m; j++)
{
cin >> l[j].o1 >> l[j].o2 >> l[j].o3;
}
char type1=NULL;
char type2=NULL;
for (int j = 0; j < m; j++)
{
int t1 = 0;
int t2 = 0;
for (int i = 0; i < n; i++)
{
if (l[j].o1 + l[j].o2 * p[i].x + l[j].o3 * p[i].y > 0)
{
if(t1==0)
{
type1 = p[i].type;
}
if (p[i].type != type1)
{
cout << "No" << endl;
break;
}
t1++;
}
if (l[j].o1 + l[j].o2 * p[i].x + l[j].o3 * p[i].y < 0)
{
if (t2 == 0)
{
type2 = p[i].type;
}
if (p[i].type != type2)
{
cout << "No" << endl;
break;
}
t2++;
}
}
if (t1 + t2 == n)
{
cout << "Yes" << endl;
}
}
return 0;
}