15 solutions

  • 3
    @ 2025-2-9 16:43:54

    蒟蒻刚学的线段树,话不多说,上线段树做法:

    #include<iostream>
    using namespace std;
    long long a[50],segt[50];
    void build(int l,int r,int num){ //递归建线段树
        if(l==r) segt[num]=a[l];
        else{
            int mid=(l+r)/2;
            build(l,mid,num*2);
            build(mid+1,r,num*2+1);
            segt[num]=segt[num*2]+segt[num*2+1];
        }
    }
    long long query(int l,int r,int lnow,int rnow,int num){
        if(l<=lnow&&rnow<=r) return segt[num];
        else{
            long long ans=0;
            int mid=(l+r)/2;
            if(l<=mid) ans+=query(l,r,lnow,mid,num*2);
            if(r>=mid+1) ans+=query(l,r,mid+1,rnow,num*2+1);
            return ans;
        }
    }
    int main(){
      cin>>a[1]>>a[2];
      build(1,2,1); //建树
      cout<<query(1,2,1,2,1); //查询区间[1,2]的和
    }
    
    

    整体思想就是把 A,BA,B 看成一个区间,最后可以便利地进行查询。

    • @ 2025-2-20 20:35:53

      不是,明明直接输出 a+ba+b 就行了为啥要用线段树呢?

      蒟蒻的能力范围在洛谷里的黄题难度\tiny 蒟蒻的能力范围在洛谷里的{\color{Yellow} 黄题} 难度

  • 2
    @ 2025-2-9 11:10:19
    #include<bits/stdc++.h>//万能头
    using namespace std;
    long long a,b;//数据类型限制
    int main(){
        cin>>a>>b;
        cout<<a+b;
        return 0;//终止(好习惯)
    }
    • 2
      @ 2025-1-28 19:54:37

      这基本上是萌新刷的第一道题吧(如果你第一道刷的是 Hello, World 就当我没说)

      废话不多说,虽然我说了句废话,但因为我又多说了句废话,所以这话还是废话^v^

      好了,上代码:

      #include <bits/stdc++.h>
      /* 万能头文件,也可以使用 iostream 或 cstdio (如果使用 cstdio 就要把 cin 和 cout 换成 scanf 和 printf ) */
      using namespace std;
      /* 调用 std ,如果使用 cstdio 可以不调用 */
      int main() {
          /* 主函数 */
          long long a, b;
          /* 定义两个长整型变量 a 和 b */
          cin >> a >> b;
          /* 输入 a 和 b */
          a += b;
          /* 此时变量 a 是原先的 a 和 b 的和 */
          cout << a;
          /* 输出,不做解释,虽然做了解释^v^ */
          return 0;
          /* 结束 */
      }
      
      /* 我大发慈悲再写一个 cstdio 的 */
      #include <cstdio>
      int main() {
          long long a, b;
          scanf("%lld %lld", &a, &b);
          printf("%lld", a + b);
          return 0;
      }
      

      注:本篇题解是在 20252025 蛇年新年将到时写的,所以在此祝大家新年快乐!

      • 1
        @ 2025-4-14 21:19:30

        程序绝对严谨,步步有原因。 求赞~~

        #include<bits/stdc++.h>
        using namespace std;
        long long k[1],a,b,ans1=0,ans2=0,ans,c1,c2;
        /*long long类型防止数据大小溢出int范围
         证明:(10^18)*4=4000000000000000000,int范围(2^31)-1=2147483647
         2147483647<4000000000000000000 所以用long long
        */
        int main(){ //主程序
            cin>>a>>b; //输入a和b
            for(int i=1;i<=a;i++)
                ans1++;  //“掰手指”算法求a的值
            for(int i=1;i<=b;i++)
                ans2++;  //同上
            if(ans1==a && ans2==b){
                c1=0; 
                c2=c1;  //处理数组k在这里所对应的下标(重要!!!)
                k[c1]+=ans1; 
                k[c2]+=ans2; //k[0]在main函数外定义,已自动清零,用k[下标]+=……避免ans1的值被覆盖,以此求和
            }
            if((ans1<0) ||
               (ans2<0) ||
               (ans2+ans1<0) //多层表达式严格扫除错误情况
            ){
                cout<<"Error"<<endl; //避免题目测试数据有误,确保答案正确
                return 0;
            }
            else if((a<=-1) ||
                    (b<=-1) || 
                    (a+b<0)  //检查初始输入值,防止运算过程中出现错误
                ){
                    cout<<"Compute Error"<<endl; //compute意思:计算
                    return 0;
                }
            int cmax=c1;
            if(c2>cmax)
                cmax=c2; //打擂法求出最大的下标,同时保证输出答案正确
            if(cmax<0){
                cout<<"Eroor";
                return 0; //return 0;提前退出程序,防止重复输出或后面输出错误答案(不要漏!!!)
            }
            for(int i=0;i<=cmax;i++)
                cout<<k[i]; //根据最大下标输出计算结果
            for(int i=0;i<=cmax;i++)
                cout<<" "; //打个格式,确保使用的下标为0(为0就不会打空格),如果错了dev编译界面能看出来
            cout<<endl; //作者习惯
            return 0;
        }
        //本人亲测已过,语言为C++17(O2)
        
        • 1
          @ 2025-4-11 22:21:29

          简单的入门题(

          看到大佬们纷纷掏出自己的复杂代码 我觉得有点过头复杂了 那么本洛谷蒟蒻也来写题解辣!(≧∇≦)ノ 由于题目限制为101810¹⁸内 所以我们使用longlonglonglong

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

          就过啦! AC记录

          • 1
            @ 2025-4-11 21:15:48

            一道简单的A+B。

            #include<bits/stdc++.h>
            using namespace std;
            int main(){
              long long a,b;
              cin>>a>>b;
              cout<<a+b;
            }
            
            • 1
              @ 2025-3-30 11:19:19
              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
                  long long n,m;cin>>n>>m;
                  cout<<m+n;
                  return 0;
              }
              

              此题需开long long

              • 1
                @ 2025-2-20 20:32:17

                很简单,a+ba+b 问题,这么水,好久没刷了。数据范围 4×1084\times 10^8,记得开个 long long\tt long\ long 保平安。

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

                AC 记录

                • 1
                  @ 2024-11-16 21:44:07

                  B2001题解

                  主要题意

                  输入 aabb 然后输出它们的和。

                  解题思路

                  无。

                  上代码!

                  #include<bits/stdc++.h>//万能头文件 
                  using namespace std;//调用std库 
                  long long a,b;//定义两个整数 
                  int main()
                  {
                  	cin>>a>>b;//输入 
                  	cout<<a+b;//输出a与b的和
                  	return 0;//好习惯 
                  }
                  
                  
                  • 0
                    @ 2025-2-6 18:10:49

                    蒟蒻的第一篇题解 题目很简单,给你两个数a、b,求他们的和然后输出。 那么既然很简单,我再贴一份快读模板

                    #include <iostream>
                    using namespace std;
                    inline long long read()// 快读模板
                    {
                    	long long x=0,f=1;
                    	char ch=getchar();
                    	while(ch<'0' || ch>'9')
                    	{
                    		if(ch=='-') f=-1;
                    		ch=getchar();
                    	}
                    	while(ch>='0' && ch<='9')
                    	{
                    		x=(x<<3)+(x<<1)+ch-'0';
                    		ch=getchar();
                    	}
                    	return x*f;
                    }
                    int main()
                    {
                    	long long a=read(),b=read();//记得要开long long 
                    	printf("%lld\n",a+b);
                    	return 0;
                    }
                    

                    最后祝大家2025新年快乐

                    • 0
                      @ 2025-2-2 0:55:26

                      题面意思就是给定一个 aabb,让我们求 a+ba+b,最重要的是,一定要开 long longlong\ long 啊,不然就只有70分喵~

                      上代码!!!

                      #include <bits/stdc++.h>
                      using namespace std;
                      long long  a, b;
                      int main(){
                      	cin>> a>> b;
                      	cout<<a+b;
                      }
                      
                      • 0
                        @ 2024-12-18 18:43:44

                        代码

                        #include<bits/stdc++.h>
                        using namespace std;
                        long long a,b;
                        int main(){
                            cin>>a>>b;
                            cout<<a+b;
                        }
                        
                        
                        • 0
                          @ 2024-11-27 21:55:43

                          题解(Python3)

                          # 一次输入两个值,保存到变量
                          a,b = input().split()
                          
                          # input()函数返回为字符串类型,转化为整型int
                          a,b = int(a),int(b)
                          
                          # 计算并输出结果
                          print(a + b)
                          
                          • 0
                            @ 2024-11-17 15:47:38

                            #indude<bits/stdc++.h> using namespcace std; int main(){ int a,b,c; cin>>a>>b; c=a+b cout<<c; return 0;

                            • @ 2024-11-19 19:41:09

                              long long,否则会爆int

                          • -5

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

                            • 1

                            Information

                            ID
                            4451
                            Time
                            1000ms
                            Memory
                            128MiB
                            Difficulty
                            1
                            Tags
                            # Submissions
                            1692
                            Accepted
                            579
                            Uploaded By