202006-1(线性分类器)
题目链接:
计算机软件能力认证考试系统http://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(稀疏向量)
题目链接:
计算机软件能力认证考试系统http://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;
}