zoukankan      html  css  js  c++  java
  • Linearization of the kernel functions in SVM(多项式模拟)

    Description

    SVM(Support Vector Machine)is an important classification tool, which has a wide range of applications in cluster analysis, community division and so on. SVM The kernel functions used in SVM have many forms. Here we only discuss the function of the form f(x,y,z) = ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j. By introducing new variables p, q, r, u, v, w, the linearization of the function f(x,y,z) is realized by setting the correspondence x^2 <-> p, y^2 <-> q, z^2 <-> r, xy <-> u, yz <-> v, zx <-> w and the function f(x,y,z) = ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j can be written as g(p,q,r,u,v,w,x,y,z) = ap + bq + cr + du + ev + fw + gx + hy + iz + j, which is a linear function with 9 variables. 

    Now your task is to write a program to change f into g.
     

    Input

    The input of the first line is an integer T, which is the number of test data (T<120). Then T data follows. For each data, there are 10 integer numbers on one line, which are the coefficients and constant a, b, c, d, e, f, g, h, i, j of the function f(x,y,z) = ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j.
     

    Output

    For each input function, print its correspondent linear function with 9 variables in conventional way on one line.
     

    Sample Input

    2
    0 46 3 4 -5 -22 -8 -32 24 27
    2 31 -5 0 0 12 0 0 -49 12
     

    Sample Output

    46q+3r+4u-5v-22w-8x-32y+24z+27
    2p+31q-5r+12w-49z+12
     
     
    题目意思:这算是一个模拟多项式吧,将给的数据填充到表达式之中,得到一个多项式。
     
    解题思路:这个题还是比较坑的,前前后后折腾了我好久,大概有下面几个坑点吧:
     
    1.第一项和最后一项要单独拿出来看待,第一项是正数没有正号,负数带着负号;最后一项如果前面全是0,最后一项是负数带着负号,非负数则不需要符号。
    2.其他每一项中系数为1和-1时,表达式应该是符号加未知数的组合。
     
     
     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5     int t,i,j,flag;
     6     int a[20];
     7     char s[15]= {'p','q','r','u','v','w','x','y','z'};
     8     scanf("%d",&t);
     9     while(t--)
    10     {
    11         flag=0;
    12         for(i=0; i<10; i++)
    13         {
    14             scanf("%d",&a[i]);
    15         }
    16         for(i=0; i<9; i++)
    17         {
    18             if(a[i]!=0)
    19             {
    20                 if(flag==0)///为第一个数
    21                 {
    22                     if(a[i]==-1)
    23                     {
    24                         printf("-");
    25                     }
    26                     else if(a[i]!=1)
    27                     {
    28                         printf("%d",a[i]);
    29                     }
    30                 }
    31                 else///不是一个数
    32                 {
    33                     if(a[i]>0)
    34                     {
    35                         if(a[i]==1)
    36                         {
    37                             printf("+");
    38                         }
    39                         else
    40                         {
    41                             printf("+%d",a[i]);
    42                         }
    43                     }
    44                     else
    45                     {
    46                         if(a[i]==-1)
    47                         {
    48                             printf("-");
    49                         }
    50                         else
    51                         {
    52                             printf("%d",a[i]);
    53                         }
    54                     }
    55                 }
    56                 printf("%c",s[i]);
    57                 flag++;
    58             }
    59             else
    60             {
    61                 continue;
    62             }
    63         }
    64         if(flag>0&&a[9]>0)
    65         {
    66             printf("+%d
    ",a[9]);
    67         }
    68         else if(flag>0&&a[9]==0)
    69         {
    70             printf("
    ");
    71         }
    72         else if(flag==0&&a[9]==0)
    73         {
    74             printf("0
    ");
    75         }
    76         else
    77         {
    78             printf("%d
    ",a[9]);
    79         }
    80     }
    81     return 0;
    82 }
     
     
     
     
     
  • 相关阅读:
    Netscape中使用event对象
    attachEvent 与 addEventListener 对同一物件事件多次绑定的触发顺序
    ADO.NET Entity Framework如何:定义具有修改存储过程的模型(实体框架)
    ADO.NET Entity Framework插入和更新数据(实体框架快速入门)
    ADO.NET Entity Framework如何:通过每种类型一个表继承以定义模型(实体框架)
    ADO.NET Entity Framework SSDL 规范
    ADO.NET Entity Framework 如何:使用 EdmGen.exe 生成对象层代码
    ADO.NET Entity Framework CSDL、SSDL 和 MSL 规范
    ADO.NET Entity Framework MSL 规范
    ADO.NET Entity Framework配置实体框架(实体框架任务)
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/9049470.html
Copyright © 2011-2022 走看看