BJTUOJ 1653 Wizard of Odds 思维, 码力

Posted FriskyPuppy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BJTUOJ 1653 Wizard of Odds 思维, 码力相关的知识,希望对你有一定的参考价值。

  题目链接: http://citel.bjtu.edu.cn/boj/problem.php?id=1653

  题目描述: 自己看吧, 懒得写了

  解题思路: 就是问一个10进制的数, 和一个2^k进制的数字谁大, 因为我觉得最快就是log2(n)了, 但是这个10进制的数是一个大数, 所以只能用字符串处理, 所以说这道题的关键就是用字符串模拟出十进制转二进制

   代码: 这个代码没有AC

技术分享
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 105;
char s1[MAXN];
char s2[MAXN];
int s3[MAXN];
int ans[MAXN];
int done;
int cnt;
int len1;

int ok( int * temp ) {
    for( int i = 0; i < len1; i++ ) {
        if( temp[i] != 0 ) return 0;
    }
    return 1;
}

void div2( int * temp, int & mod ) {
    int flag = 0;
    for( int i = 0; i < len1; i++ ) {
        if( flag ) temp[i] += 10;
        if( temp[i] % 2 ) flag = 1;
        else flag = 0;
        temp[i] = temp[i] / 2;
    }
    mod = flag;
}

void solve( int * temp ) {
    
    if( done ) return;
    if( ok(temp) ) {
        done = 1;
        return;
    }
    int mod = 0;
    div2(temp, mod);
    ans[cnt++] = mod;
    solve(temp);
}
int main() {
    while( scanf( "%s%s", s1, s2 ) != EOF ) {
        memset(s3, 0, sizeof(s3));
        memset(ans, 0, sizeof(ans));
        done = 0;
        cnt = 0;
        len1 = (int)strlen(s1);
        int len2 = (int)strlen(s2);
        if( len2 >= 4 ) {
            cout << "Your wish is granted!" << endl;
            continue;
        }
        int num2 = atoi(s2);
        for( int i = 0; i < len1; i++ ) {
            s3[i] = (int)s1[i]-48;
        }
        solve(s3);
//        for( int i = cnt-1; i >= 0; i-- ) {
//            cout << ans[i] << " ";
//        }
//        cout << endl;
//        cout << cnt-1 << " " << num2 << endl;
        if( cnt > num2+1 ) {
            cout << "You will become a flying monkey!" << endl;
        }
        else if( cnt < num2+1 ) {
            cout << "Your wish is granted!" << endl;
        }
        else {
            int flag = 1;
            for( int i = 1; i < cnt-1; i++ ) {
                if( ans[i] != 0 ) {
                    flag = 0;
                    break;
                }
            }
        
            if( !flag ) {
                cout << "You will become a flying monkey!" << endl;
            }
            else {
                cout << "Your wish is granted!" << endl;
            }
        }
    }
}
View Code

  思考: 我好像像个傻逼一样了......这题应该这么做?

 

以上是关于BJTUOJ 1653 Wizard of Odds 思维, 码力的主要内容,如果未能解决你的问题,请参考以下文章

8.21 :odd??:nth-of-type??

wizard怎么念

Odd Numbers of Divisors

LeetCode --- 1588. Sum of All Odd Length Subarrays 解题报告

LeetCode --- 1588. Sum of All Odd Length Subarrays 解题报告

LeetCode --- 1588. Sum of All Odd Length Subarrays 解题报告