CCF-CSP题
题号2020-06-01
题目背景
#源码
#include<iostream>
#include<string>
using namespace std;
//是否对n组数据分割成功的函数
typedef struct query{
int c1;
int c2;
int c3;
}query;
typedef struct location{
int x;
int y;
char kind;
}location;
//分割函数,输入参数为一组线条数据,和所有点的信息
bool iscut(int c1, int c2, int c3, location *spot, int n)//成功分割,则返回true;n个点
{
int flagA,flagB;
for(int i=0;i<n;++i)
{
if(spot[i].kind=='A')
{
flagA=c1+c2*spot[i].x+c3*spot[i].y;
break;
}
}
for(int i=0;i<n;++i)
{
if(spot[i].kind=='B')
{
flagB=c1+c2*spot[i].x+c3*spot[i].y;
break;
}
}
if((flagA>0 && flagB>0)||(flagA<0 && flagB<0)||(flagA==0)||(flagB==0))//如果A,B类同号,或者A,B类有一个为0,则直接判定不能成功分割
{
return false;
}
if(flagA>0)//A类大于零,B类小于零
{
for(int i=0;i<n;++i)
{
if(spot[i].kind=='A' && (c1+c2*spot[i].x+c3*spot[i].y)<=0)
{
return false;
}
if(spot[i].kind=='B' && (c1+c2*spot[i].x+c3*spot[i].y)>=0)
{
return false;
}
}
return true;
}
else//A类小于0,B类大于0
{
for(int i=0;i<n;++i)
{
if(spot[i].kind=='A' && (c1+c2*spot[i].x+c3*spot[i].y)>=0)
{
return false;
}
if(spot[i].kind=='B' && (c1+c2*spot[i].x+c3*spot[i].y)<=0)
{
return false;
}
}
return true;
}
}
int main()
{
int m,n;
cin>>n>>m;
query line[m];
location spot[n];
for(int i=0;i<n;++i)//先输入点的信息并储存
{
cin>>spot[i].x>>spot[i].y>>spot[i].kind;
}
for(int i=0;i<m;++i)//输入线的信息并储存
{
cin>>line[i].c1>>line[i].c2>>line[i].c3;
}
for(int i=0;i<m;++i)
{
if(iscut(line[i].c1,line[i].c2,line[i].c3,spot,n))
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
return 0;
}