hdu 5095 Linearization of the kernel functions in SVM(模拟,分类清楚就行)

题意:

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.

样例:

2
0 46 3 4 -5 -22 -8 -32 24 27                         --->                        46q+3r+4u-5v-22w-8x-32y+24z+27

2 31 -5 0 0 12 0 0 -49 12                             --->                        2p+31q-5r+12w-49z+12

代码:

char b[15]={'p','q','r','u','v','w','x','y','z'};
int a[15];
int T;

int main(){
    //freopen("test.in","r",stdin);
    cin>>T;
    while(T--){
        rep(i,0,9) scanf("%d",&a[i]);
        int c=-1;
        rep(i,0,8) if(a[i]!=0) {c=i; break;}
        if(c==-1){
            printf("%d
",a[9]);
            continue;
        }
        if(abs(a[c])==1)
            if(a[c]>0) printf("%c",b[c]); else printf("-%c",b[c]);
        else
            printf("%d%c",a[c],b[c]); ++c;
        rep(i,c,8){
            if(a[i]==0) continue;
            if(abs(a[i])==1)
                if(a[i]==1) printf("+%c",b[i]); else printf("-%c",b[i]);
            else
                if(a[i]>0) printf("+%d%c",a[i],b[i]); else printf("%d%c",a[i],b[i]);
        }
        if(a[9]!=0){
            if(a[9]>0) printf("+%d
",a[9]); else printf("%d
",a[9]);
        }
        else
            printf("
");
    }
    //fclose(stdin);
}
原文地址:https://www.cnblogs.com/fish7/p/4085144.html