hdu 5095 Linearization of the kernel functions in SVM(模拟)

Linearization of the kernel functions in SVM

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 206    Accepted Submission(s): 109

Problem 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 和 1 的情况 , 考虑清楚就ok了 。

#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 15 ;
const char ch[maxn] = {'p','q','r','u','v','w','x','y','z','j'};

int a[maxn];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        for(int i=0; i<10; i++) scanf("%d",&a[i]);
        a[10]=99;
        int cnt=0;
        while(a[cnt]==0) cnt++;
        if(cnt==10)
        {
            cout<<"0"<<endl;
            continue;
        }

        if(cnt==9)  cout<<a[cnt];
        else
        {
            if(a[cnt]==1) cout<<ch[cnt];
            else if(a[cnt]==-1)  cout<<"-"<<ch[cnt];
            else  cout<<a[cnt]<<ch[cnt];
        }

        for(int i=cnt+1; i<10; i++)
        {
            if(a[i]==0)  continue;
            if(a[i]>0) cout<<"+";
            if(i==9)  cout<<a[i];
            else
            {
                if(a[i]==1) cout<<ch[i];
                else if(a[i]==-1)  cout<<"-"<<ch[i];
                else  cout<<a[i]<<ch[i];
            }
        }
        cout<<endl;
    }
    return 0;
}
时间: 2024-11-06 23:21:18

hdu 5095 Linearization of the kernel functions in SVM(模拟)的相关文章

HDU 5095 Linearization of the kernel functions in SVM(模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5095 Problem 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

hdu 5095 Linearization of the kernel functions in SVM 坑多的水题 细节

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5095 几个坑 系数为正负1是不输出系数(比赛时wa到死) 0时不输出但全零时要输出0 加号和减号的控制 #include <cstring> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #in

模拟 HDOJ 5095 Linearization of the kernel functions in SVM

题目传送门 1 /* 2 题意:表达式转换 3 模拟:题目不难,也好理解题意,就是有坑!具体的看测试样例... 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <iostream> 8 #include <cstring> 9 #include <cmath> 10 #include <string> 11 #include <vector> 12 #i

HDU5095——水过——Linearization of the kernel functions in SVM

Problem 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 t

hdoj-2095-Linearization of the kernel functions in SVM

Linearization of the kernel functions in SVM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2239 Accepted Submission(s): 599 Problem Description SVM(Support Vector Machine)is an important classif

hdu---5095---Linearization of the kernel functions in SVM

http://acm.hdu.edu.cn/showproblem.php?pid=5095 分析:当a[i]不为0的时候,就有输出; 输出内容:1.系数为正数且不是第一个位置输出一个'+'; 2.当系数为-1时且不是最后一个常数时输出一个'-'; 3.系数不是-1或1或者是最后那个常数时输出这个数: 4.最后一个位置没有字符要输出. Problem Description SVM(Support Vector Machine)is an important classification too

hdu 5095

Linearization of the kernel functions in SVM Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1001    Accepted Submission(s): 286 Problem Description SVM(Support Vector Machine)is an important cl

HDU 4274 Spy&#39;s Work (树形DP,模拟)

题意: 给定一棵树,每个节点代表一个员工,节点编号小的级别就小,那么点1就是boss了.接下来给出对m个点的限制,有3种符号分别是op=“大于/小于/等于”,表示以第i个点为根的子树所有人的工资之和 大于/小于/等于 x,要求判断m个限制是否冲突了.注意每个员工的工资下限是1,而无上限.ps:可能出现对同个点多个限制,注意取交集. 思路: 很水的题嘛,想复杂了.注意限制是针对整棵子树的!所以我们只需要算出这棵子树的范围,再判断是否和所给的限制有冲突,如果没有冲突的话还得取“所给限制”与“计算出的

HDU 4588 Count The Carries(找规律,模拟)

题目 大意: 求二进制的a加到b的进位数. 思路: 列出前几个2进制,找规律模拟. #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <stack> #include <vector> using namespace std; int main() { int