zoukankan      html  css  js  c++  java
  • 线性分类器

     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 struct DOT
     5 {
     6     int x, y;
     7     int type;//A1,B0
     8 };
     9 int main()
    10 {
    11     int dot, judge;
    12     cin >> dot >> judge;
    13     struct DOT* dp = new struct DOT[dot];
    14     for (int i = 0; i < dot; i++)
    15     {
    16         cin >> dp[i].x >> dp[i].y;
    17         char tempc;
    18         cin >> tempc;
    19         if (tempc == 'A')
    20             dp[i].type = 1;
    21         else
    22             dp[i].type = 0;
    23     }
    24     for (int i = 0; i < judge; i++)
    25     {
    26         int a, b, c;
    27         bool out = true;
    28         int flag = 0;//A: >0
    29         cin >> a >> b >> c;
    30         int t = a + dp[0].x * b + dp[0].y * c;
    31         if (t == 0)
    32         {
    33             out = false;
    34         }
    35         else
    36         {
    37             if (dp[0].type == 1)//A
    38             {
    39                 if (t > 0)
    40                 {
    41                     flag = 0;
    42                 }
    43                 else
    44                 {
    45                     flag = 1;
    46                 }
    47             }
    48             else
    49             {
    50                 if (t > 0)
    51                 {
    52                     flag = 1;
    53                 }
    54                 else
    55                 {
    56                     flag = 0;
    57                 }
    58             }
    59             for (int j = 1; j < dot; j++)
    60             {
    61                 t = a + dp[j].x * b + dp[j].y * c;
    62                 if (flag == 0)
    63                 {
    64                     if ((dp[j].type == 1 && t < 0) || (dp[j].type == 0 && t > 0))
    65                     {
    66                         out = false;
    67                         break;
    68                     }      
    69                 }
    70                 else
    71                 {
    72                     if ((dp[j].type == 1 && t > 0) || (dp[j].type == 0 && t < 0))
    73                     {
    74                         out = false;
    75                         break;
    76                     }
    77                 }
    78             }
    79             if (out)cout << "Yes" << endl;
    80             else cout << "No" << endl;
    81         }
    82     }
    83     return 0;
    84 }
    9 3
    1 1 A
    1 0 A
    1 -1 A
    2 2 B
    2 3 B
    0 1 A
    3 1 B
    1 3 B
    2 0 A
    0 2 -3
    -3 0 2
    -3 1 1
  • 相关阅读:
    【动态规划】51nod1780 完美序列
    【树形dp】bzoj4726: [POI2017]Sabota?
    初涉manacher
    【数位dp】bzoj3131: [Sdoi2013]淘金
    【思维题 kmp 构造】bzoj4974: [Lydsy1708月赛]字符串大师
    web框架
    Bootstrap补充
    jQuery之jQuery扩展和事件
    JQuery之文档操作
    JQuery之属性操作
  • 原文地址:https://www.cnblogs.com/2020R/p/13738944.html
Copyright © 2011-2022 走看看