啊?7个mle!?

P1001 A+B Problem

Jokersheng @ 2024-07-24 18:00:23

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

long long a,b,n;

void dfs(long long a){
    if(a==1){
        n++;
        return;
    }
    if(a%2==0){
        dfs(a/2);
        dfs(a/2);
    }else{
        dfs((a+1)/2);
        dfs(a/2);
    }
    return;
}

int main(){
    cin>>a>>b;
    dfs(a);
    dfs(b);
    cout<<n;
    return 0;
}

by Jokersheng @ 2024-07-24 18:04:20

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

long long c,b,n;

void dfs(long long a){
    if(a==1||a==-1){
        n+=a;
        return;
    }
    if(a%2==0){
        dfs(a/2);
        dfs(a/2);
    }else{
        dfs((a+1)/2);
        dfs(a/2);
    }
    return;
}

int main(){
    cin>>c>>b;
    dfs(c);
    dfs(b);
    cout<<n;
    return 0;
}

by yintaocheng @ 2024-07-24 18:04:47

这玩意空间复杂度O(n)的,当然MLE了


by Jokersheng @ 2024-07-24 18:04:50

emo了,改了也不对


by EmptyAlien @ 2024-07-24 18:23:36

@shengshengzqs 会爆栈


by alsk_3945 @ 2024-08-03 08:23:04

@shengshengzqs我的AC代码见下:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,s;
    cin>>a>>s;
    cout<<a+s<<endl;
    return 0;
}

|