51nod 1491 黄金系统

得益于数据量小,用比较丑的暴力姿势也过了。。。
找规律会发现 qn=qn1+qn2 ,我是把每个高位的1分解成两个低位的1,多分解几次,暴力水过。
这里的暴力姿势我感觉比较好:
http://blog.csdn.net/mengxiang000000/article/details/53538476

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100100;
char str1[MAXN];
int len1;
char str2[MAXN];
int len2;

int main()
{
    char ch;
    char *s1 = str1;
    char* s2 = str2;
    while((ch = getchar()) != '\n')
    {
        if(ch == '0' && len1 == 0) continue;
        str1[len1++] = ch;
    }
    str1[len1] = '\0';
    while((ch = getchar()) != '\n')
    {
        if(ch == '0' && len2 == 0) continue;
        str2[len2++] = ch;
    }
    str2[len2] = '\0';
    for(int k = 0; k < 10; ++k)
    {
        for(int i = len1-1; i > 1; --i)
        {
            if(str1[i] == '0' && str1[i-1] == '0' && str1[i-2] == '1')
            {
                str1[i] = str1[i-1] = '1';
                str1[i-2] = '0';
            }
        }

        for(int i = len2-1; i > 1; --i)
        {
            if(str2[i] == '0' && str2[i-1] == '0' && str2[i-2] == '1')
            {
                str2[i] = str2[i-1] = '1';
                str2[i-2] = '0';
            }
        }
    }
    while((*s1) == '0')
    {
        len1--;
        ++s1;
    }
    while((*s2) == '0')
    {
        len2--;
        ++s2;
    }
    if(len1 > len2)
    {
        printf(">\n");
        return 0;
    }
    else if(len1 < len2)
    {
        printf("<\n");
        return 0;
    }
    int res = strcmp(s1,s2);
    if(res == 0) printf("=\n");
    else if(res > 0) printf(">\n");
    else printf("<\n");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值