【CSP认证】202006_1 线性分类器

参考文章
https://www.it610.com/article/1291013626328588288.htm

题目描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
巧妙的点
用ch1和ch2分别记录m种对应参数的情况下两个类别(大于0和小于0)的字符表示,以此推出该参数是否可取。

代码实现

//202006_1  线性分类器
#include<iostream>
using namespace std;

int n,m; // 点;查询个数 

struct Node{
	int x,y;
	char ch;
}node[1002]; //  n个点 

// 判断函数 
bool judge(int x0,int x1,int x2)
{
	char ch1='c',ch2='d'; // 初始设为除'A''B'外的任意不同字符 
	// 依次遍历 n 个点 
	for(int i=0;i<n;i++){ 
		int tmp = x0+x1*node[i].x+x2*node[i].y; 
		if(tmp==0) return false; // x1和x2不能同时为0
		if(tmp>0) ch1 = node[i].ch; // ch1标记>0的字符 
		else if(tmp<0) ch2 = node[i].ch; // ch2标记<0的字符
		// ch1和ch2不能相同
		if(ch1==ch2) return false; 
	} 
	return true;
}

int main()
{
	int x0,x1,x2;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>node[i].x>>node[i].y>>node[i].ch; 
	}
	// 依次判断 m 种情况 
	for(int i=0;i<m;i++){
		cin>>x0>>x1>>x2;
		if(judge(x0,x1,x2)) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值