CCF-CSP认证(202006)题目

202006-1(线性分类器)

题目链接:

计算机软件能力认证考试系统icon-default.png?t=N7T8http://118.190.20.162/view.page?gpid=T105

题意:

思路:


        题目就是要求我们判断直线是否可以将A、B类分开,我们直接代入每个类别中的x和y即可,如果值的正负一样就是一类,如果可以区分A和B,就是可以,否则就是不行。

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<cmath>
#include<unordered_set>

#define PII pair<int, int>
#define ll long long

using namespace std;

const int N = 110;

int n, m;
int x, y;
char ty;
int a, b, c;
vector<PII > A, B;

void solve()
{
	cin >> n >> m;
	
	for (int i = 0; i < n; ++ i)
	{
		cin >> x >> y >> ty;
		if(ty == 'A') A.push_back({x, y});
		else B.push_back({x, y});
	}
	
	int xn = 0, yn = 0, ais = 0, bis = 0;
	
	while(m --)
	{
		cin >> a >> b >> c;
		ais = 0, bis = 0;
		bool st = true;
		
		for (int i = 0; i < A.size() && st; ++ i)
		{
			xn = A[i].first, yn = A[i].second;
			
			if(a + xn * b + yn * c < 0) 
			{
			    if(ais == 0) ais = -1;
			    else if(ais != -1) st = false;
			}
			else 
			{
			    if(ais == 0) ais = 1;
			    else if(ais != 1) st = false;
			}
		}
		if(!st) 
		{
			cout << "No" << endl;
			continue;
		}

		for (int i = 0; i < B.size() && st; ++ i)
		{
		    xn = B[i].first, yn = B[i].second;
		    
		    if(a + xn * b + yn * c > 0) 
		    {
		        if(ais == -1)
		        {
		            if(bis == 0) bis = 1;
		            else if(bis != 1) st = false;
		        }
		        else st = false;
		    }
		    else 
		    {
		        if(ais == 1)
		        {
		            if(bis == 0) bis = -1;
		            else if(bis != -1) st = false;
		        }
		        else st = false;
		    }
		}
		if(st) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	
//	int T;
//	cin >> T;
//	
//	while(T--)
//	{
		solve();
//	}
	
	return 0;
}

202006-2(稀疏向量)

题目链接:

计算机软件能力认证考试系统icon-default.png?t=N7T8http://118.190.20.162/view.page?gpid=T104

题意:

思路:

         先将u存在map里,而且把u的index存在unordered_set里,然后输入v,对v的每一个index进行在unordered_set中查找,如果找到了,那就将ans += u.value * v.value,最后输出即可,不过要注意了,ans一定记得开long long,不然会悔恨终生。

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<cmath>
#include<unordered_set>

#define PII pair<int, int>
#define int long long

using namespace std;

const int N = 110;

int n, a, b, ans;
map<int, int> A;
unordered_set<int> aa;

void solve()
{
	cin >> n >> a >> b;
	int x, y;
	
	for (int i = 0; i < a; ++ i)
	{
		cin >> x >> y;
		A[x] = y;
		aa.insert(x);
	}
	
	for (int i = 0; i < b; ++ i)
	{
		cin >> x >> y;
		if(aa.count(x)) ans += A[x] * y;
	}
	
	cout << ans << endl;
}

signed main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	
//	int T;
//	cin >> T;
//	
//	while(T--)
//	{
		solve();
//	}
	
	return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dawpro_加薪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值