2 solutions

  • 2
    @ 2025-5-21 17:31:34

    这是一篇测试性题解

    #include <bits/stdc++.h> //万能头文件
    using namespace std; //命名空间,省略std::
    int main(){
      int a,b; //定义a和b
      cin>>a>>b; //读入a和b
      cout<<a+b; //在输出同时计算
      return 0; //程序结束(一定要写这一行!!!)
    }
    
    • 1
      @ 2025-8-19 16:58:40

      一眼二分查找。

      注意到枚举i,j,当i,j增大时i+j具有单调性,所以能够用二分来作答。

      代码如下:

      #include<iostream>
      using namespace std;
      long long a,b;
      int main(){
      	long long l=-2e9,r=2e9,mid;
      	cin>>a>>b;
      	while(l<=r){
      		mid=(l+r)>>1;
      		if(a+b==mid){
      			cout<<mid;
      			break;
      		}
      		else if(a+b<mid){
      			r=mid-1;
      		}
      		else if(a+b>mid){
      			l=mid+1;
      		}
      	}
      	return 0;
      }
      
      • 1

      Information

      ID
      1
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      1
      Tags
      # Submissions
      30
      Accepted
      10
      Uploaded By