题目解题思路代码
题目
试题编号: 202006-1
试题名称: 线性分类器
时间限制: 1.0s
内存限制: 512.0MB
使用语言:C++
得分:100
解题思路
由题目可得
代码#include#include using namespace std; struct Point { int x; int y; char type; } P[1000]; struct Line { int a; int b; int c; } L[20]; int main() { int n, m; // Point P[1000]; // Line L[20]; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d %d %c", &P[i].x, &P[i].y, &P[i].type); //多打一个空格解决读入空格的问题 } string output[20]; for (int i = 0; i < m; i++) { scanf("%d%d%d", &L[i].c, &L[i].a, &L[i].b); char AD = 'M', BD = 'M'; for (int j = 0; j < n; j++) { int jude = (P[j].x) * (L[i].a) + (P[j].y) * (L[i].b) + (L[i].c); char temp; if (jude > 0) { temp = 'U'; } else { temp = 'D'; } if (P[j].type == 'A') { if (AD == 'M') { AD = temp; } else if (AD == temp) { output[i] = "Yes"; } else { output[i] = "No"; break; } } if (P[j].type == 'B') { if (BD == 'M') { BD = temp; } else if (BD == temp) { output[i] = "Yes"; } else { output[i] = "No"; break; } } } } for (int k = 0; k < m - 1; k++) { printf("%sn", output[k].c_str()); //只要在变量名后加.c_str()即可将string类型等效为C中的字符数组类型进行输入输出。 } printf("%s", output[m - 1].c_str()); //system("pause"); return 0; }



