試題編號: 202006-1
試題名稱: 線性分類器
時間限制: 1.0s
記憶體限制: 512.0MB



問題鏈接:CSP202006-1 線性分類器
問題簡述:(略)
問題分析:判定點集合是否都在同一側,可以將點代入決議式,如果都>0或都<0則在同一側,
程式說明:(略)
參考鏈接:(略)
題記:(略)
AC的C++語言程式如下:
/* CSP202006-1 線性分類器 */
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
struct Point {
int x, y;
} a[N], b[N];
int acnt, bcnt;
int main()
{
int n, m;
scanf("%d%d", &n, &m);
acnt = bcnt = 0;
for(int i = 0; i < n; i++) {
int x, y;
char type2[2];
scanf("%d%d%s", &x, &y, type2);
if(type2[0] == 'A') {
a[acnt].x = x;
a[acnt++].y = y;
} else if(type2[0] == 'B') {
b[bcnt].x = x;
b[bcnt++].y = y;
}
}
for(int i = 1; i <= m; i++) {
bool side, ans = true;
int t0, t1, t2;
scanf("%d%d%d", &t0, &t1, &t2);
if(acnt)
side = t0 + a[0].x * t1 + a[0].y * t2 > 0;
else
side = t0 + b[0].x * t1 + b[0].y * t2 > 0;
// 判定A點集合是否在同一側
for(int i = 1; i < acnt; i++)
if(t0 + a[i].x * t1 + a[i].y * t2 > 0 != side) {
ans = false;
break;
}
// 判定B點集合是否在同一側
if(ans) {
for(int i = 0; i < bcnt; i++)
if(t0 + b[i].x * t1 + b[i].y * t2 > 0 == side) {
ans = false;
break;
}
}
printf(ans ? "Yes\n" : "No\n");
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/46672.html
標籤:其他
上一篇:arpr破解器我匯入檔案就未回應
下一篇:如何進行相機標定的仿真
