HDU5095 Linearization of the kernel functions in SVM(模拟)

Linearization of the kernel functions in SVM

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5095

解题思路:

很坑的一道模拟题,注意1,-1和全为0时的结果。

我写了两份代码,一份思路比较清晰,一份比较乱,勿喷。

AC代码(比较清晰的):

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    char b[]={'p','q','r','u','v','w','x','y','z'};
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int x,i,flag=0;
        for(i=0;i<9;i++)
        {
            scanf("%d",&x);
            if(x==0)
                continue;
            flag++;
            if(flag==1||x<0)
            {
                if(x==-1)
                    printf("-%c",b[i]);
                else if(x==1)
                    printf("%c",b[i]);
                else
                    printf("%d%c",x,b[i]);
            }
            else
            {
                if(x==1)
                    printf("+%c",b[i]);
                else
                    printf("+%d%c",x,b[i]);
            }
        }
        scanf("%d",&x);
        if(x)
        {
            if(flag&&x>0)
                printf("+%d",x);
            else
                printf("%d",x);
        }
        if(flag==0&&x==0)
            printf("0");
        printf("\n");

    }
    return 0;
}

AC代码(比较乱的):

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int i=1,x,flag=1;
        char c='p';
        scanf("%d",&x);
        if(x!=0)
        {
            flag=0;
            if(x==1)
                printf("%c",c);
            else if(x==-1)
                printf("-%c",c);
            else
                printf("%d%c",x,c);
        }
        else
        {
            while(x==0&&i<9)
            {
                scanf("%d",&x);
                i++;c++;
                if(c=='s')
                    c+=2;
                if(x!=0)
                {
                    flag=0;
                    if(x==1)
                        printf("%c",c);
                    else if(x==-1)
                        printf("-%c",c);
                    else
                    printf("%d%c",x,c);
                }
            }
        }
        for(;i<9;i++)
        {
            scanf("%d",&x);
            c++;
            if(c=='s')
                c+=2;
            if(x!=0)
            {
                flag=0;
                if(x==1)
                    printf("+%c",c);
                else if(x==-1)
                    printf("-%c",c);
                else
                {
                    if(x>0)
                        cout<<'+';
                    printf("%d%c",x,c);
                }
            }
        }
        scanf("%d",&x);
        if(flag)
            printf("%d",x);
        else if(x!=0)
        {
            if(x<0)
                printf("%d",x);
            else
                printf("+%d",x);
        }
        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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值