二分 50分求助

P1001 A+B Problem

somek_ @ 2023-10-12 19:06:55

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

int main() {
    int a, b;
    cin >> a >> b;
    long long l = 1, r = pow(2, 31) - 2;
    while (l < r) {
        long long mid = (l + r) / 2;
        if (a + b <= mid)
            r = mid;
        else
            l = mid + 1;
    }
    cout << r;
}

by GreenMelon @ 2023-10-12 19:19:27

...

我是胡桃的狗!

我是胡桃的狗!

我是胡桃的狗!

不瞒着了


by return_second @ 2023-10-13 16:16:55

真傻。 人家说了结果小于1e9!!!

#include <iostream>
using namespace std;

int main()
{
   int a,b;
   scanf("%d%d",&a,&b);
   printf("%d",a+b);
   return 0;
}

by return_second @ 2023-10-13 16:18:17

@I_mAmonkey

傻不傻?


by zhanghy123 @ 2023-10-14 11:54:52

@I_mAmonkey 有负数,得判定吧


by zhanghy123 @ 2023-10-14 11:56:07

@GeorgeCHN 整活而已别急眼啊


by _O_v_O_ @ 2023-10-15 16:17:40

@keyanzhe l不应该是-r吗


by DBL_MAX @ 2023-10-15 16:48:21

这样就够了:

#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    cout<<a+b;
    return 0;
}

by Zaoly @ 2023-10-20 15:25:44

有负数哦!


by lijingshu_304775 @ 2023-10-20 18:19:55

#include<iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    cout << a + b;
    return 0;
}

看不懂的看这里:题解传送门


by zhanghe724_1 @ 2023-10-20 19:37:02

你们都闲的是吧,那我用__```cpp

include<bits/stdc++.h>

using namespace std; inline int128 read(){ int128 x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ x=x10+ch-'0'; ch=getchar(); } return xf; } inline void write(int128 x){ if(x<0){ putchar('-'); x=-x; } if(x>9)write(x/10); putchar(x%10+'0'); } int main(){ int128 a=read(); __int128 b=read(); write(a+b); return 0; }


int128做这题不过分吧

上一页 | 下一页