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 used in SVM have many forms. Here we only discuss the function of the form f(x,y,z)
= ax^2 + by^2 + cz^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 + cz^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 + cz^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

Source

2014上海全国邀请赛——题目重现(感谢上海大学提供题目)

Recommend

hujie   |   We have carefully selected several similar problems for you:  5098 5097 5096 5094 5093

PS:

一道比较坑的模拟题!

注意1和-1 的情况!

代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    int M;
    int a[17];
    char b[17] = {'#','p','q','r','u','v','w','x','y','z'};
    scanf("%d",&M);
    getchar();
    while(M--)
    {
        for(int k = 1; k <= 10; k++)
        {
            scanf("%d",&a[k]);
        }
        int cont = 0;
        int flag = 0;
        for(int k = 1; k < 10; k++)
        {
            if(a[k]==0)
                continue;
            cont++;
            if(cont == 1)
            {
                if(a[k] != 1 && a[k] != -1)
                    printf("%d%c",a[k],b[k]);
                else if(a[k] == 1)
                    printf("%c",b[k]);
                else if(a[k] == -1)
                    printf("-%c",b[k]);
                flag = 1;
            }
            else
            {
                if(a[k] > 0)
                    printf("+");
                if(a[k] != 1 && a[k] != -1)
                    printf("%d%c",a[k],b[k]);
                else if(a[k] == 1)
                    printf("%c",b[k]);
                else if(a[k] == -1)
                    printf("-%c",b[k]);
                flag = 1;
            }
        }
        if(a[10])
        {
            if(a[10] > 0 && flag)
                printf("+");
            printf("%d",a[10]);
            flag = 1;
        }
        if(!flag)//没有答案
            printf("0");
        printf("\n");
    }
    return 0;
}
/*
99
0 0 0 0 0 0 0 0 0 -1
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
-1 0 0 0 0 0 0 0 0 0
-1 -1 -1 -41 -1 -1 -1 -1 -1 -1
-1 5 -2 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
0 0 0 0 0 -1 -1 -1 -1 -1
0 0 0 0 0 1 1 1 1 1
1 1 1 1 1 0 0 0 0 0
-1 -1 -1 -1 -1 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0
*/
时间: 2024-10-24 18:08:14

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

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 cl

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