首页 > 其他 > 详细

hdoj-2095-Linearization of the kernel functions in SVM

时间:2015-08-13 15:43:13      阅读:361      评论:0      收藏:0      [点我收藏+]

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

Source

Recommend
hujie | We have carefully selected several similar problems for you: 5379 5378 5377 5376 5375

主要是好多细节需要考虑:1. 对于第一个输出的正数的正号是否要输出; 2. 系数为 1或 -1的情况;3 . 0的处理(如果系数都为0,要输出最后一位的0)

#include<stdio.h>
char s[10]={'p','q','r','u','v','w','x','y','z'};
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int a,k=0;
		for(int i=0;i<9;++i){
			scanf("%d",&a);
			if(a==0) continue;
			//else k++;
			if(a==1||a==-1) {
				if(a==1&&k) printf("+");
				//else if(a==1&&k==0) ;
				else if(a==-1)printf("-");
				printf("%c",s[i]);  k++;
				continue;
			}
			if(a>0&&k) printf("+");
			printf("%d",a);
			printf("%c",s[i]);
			k++;
		}
		scanf("%d",&a);
                if(a==1||a==-1) {
				if(a==1&&k==0) printf("1");
				else if(a==1&&k) printf("+1");
				else if(a==-1)printf("-1");
				printf("\n");
				//continue;
		}
		else {
			if(a==0){
				if(k==0) printf("0\n");
				else printf("\n");
				continue;
			}
			if(a>0&&k) printf("+");
			printf("%d",a);
			printf("\n");
		}
		
	}
	return 0;
}




版权声明:本文为博主原创文章,未经博主允许不得转载。

hdoj-2095-Linearization of the kernel functions in SVM

原文:http://blog.csdn.net/qq_18062811/article/details/47613205

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!