137 条题解

  • -2
    @ 2023-4-8 20:33:53

    很简单,线段树模板题。

    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    int x, y, a[100005];
    struct node {
    	int l, r, w, tag;
    } tr[400005];
    inline bool inrange(int l1, int r1, int l2, int r2) {
    	return (l1 >= l2) && (r1 <= r2);
    }
    inline bool outofrange(int l1, int r1, int l2, int r2) {
    	return (l1 > r2) || (l2 > r1);
    }
    inline void pushup(int u) {
    	tr[u].w = tr[u * 2].w + tr[u * 2 + 1].w;
    }
    inline void build(int u, int l, int r) {
    	if (l == r) {
    		tr[u].w = a[l];
    		return;
    	}
    	int mid = l + r >> 1;
    	build(u * 2, l, mid); build(u * 2 + 1, mid + 1, r);
    	pushup(u);
    }
    inline int query1(int u, int l, int r, int p) {
    	if (l == r) {
    		return tr[u].w;
    	} else {
    		int mid = l + r >> 1;
    		if (p <= mid) return query1(u * 2, l, mid, p);
    		else return query1(u * 2 + 1, mid + 1, r, p);
    	}
    }
    inline void update1(int u, int l, int r, int p, int x) {
    	if (l == r) {
    		tr[u].w += x;
    	} else {
    		int mid = l + r >> 1;
    		if (mid >= p) update1(u * 2, l, mid, p, x);
    		else update1(u * 2 + 1, mid + 1, r, p, x);
    	}
    }
    inline void maketag(int u, int len, int x) {
    	tr[u].tag += x;
    	tr[u].w += len * x;
    }
    inline void pushdown(int u, int l, int r) {
    	int mid = l + r >> 1;
    	maketag(u * 2, mid - l + 1, tr[u].tag);
    	maketag(u * 2 + 1, r - mid, tr[u].tag);
    	tr[u].tag = 0;
    }
    inline int query(int u, int l1, int r1, int l2, int r2) {
    	if (inrange(l1, r1, l2, r2)) {
    		return tr[u].w;
    	} else if (!outofrange(l1, r1, l2, r2)) {
    		int mid = l1 + r1 >> 1;
    		pushdown(u, l1, r1);
    		return query(u * 2, l1, mid, l2, r2) + query(u * 2 + 1, mid + 1, r1, l2, r2);
    	}
    }
    inline void update(int u, int l1, int r1, int l2, int r2, int x) {
    	if (inrange(l1, r1, l2, r2)) {
    		maketag(u, r1 - l1 + 1, x);
    	} else if (!outofrange(l1, r1, l2, r2)) {
    		int mid = l1 + r1 >> 1;
    		pushdown(u, l1, r1);
    		update(u * 2, l1, mid, l2, r2, x);
    		update(u * 2 + 1, mid + 1, r1, l2, r2, x);
    		pushup(u);
    	}
    }
    signed main() {
        cin >> x >> y;
        build(1, 1, 1);
        update1(1, 1, 1, 1, x);
        update1(1, 1, 1, 1, y);
        cout << query1(1, 1, 1, 1);
        return 0;
    }
    
  • -2
    @ 2023-3-23 20:06:20
    #include<bits/stdc++.h>//万能头文件
    using namespace std;//使用标准命名空间
    int main()//主函数
    {
    	int a,b;
    	cin>>a>>b;
    	cout<<a+b;
    	return 0;
    }
    ~~太简单了~~
    
    • -2
      @ 2023-3-20 15:48:05

      很简单,先用字符串存放数据,在从低位开始算,两两相加,逢十进一。

      ~代码才40行,不多~

      #include<bits/stdc++.h>
      using namespace std;
      int a[1000001],b[1000001],c[1000001],j;
      bool x=false;
      char s[1000001],ss[1000001];
      int main() 
      {
      	memset(a,0,sizeof(a));
      	memset(b,0,sizeof(b));
      	memset(c,0,sizeof(c));
      	scanf("%s%s",s,ss);
      	a[0]=strlen(s);
      	b[0]=strlen(ss);
      	for(int i=1; i<=a[0]; i++) 
      	a[i]=s[a[0]-i]-'0';
      	for(int i=1; i<=b[0]; i++) 
      	b[i]=ss[b[0]-i]-'0';
      	for(j=1; j<=max(a[0],b[0])+1; j++) 
      	{
      		c[j]=a[j]+b[j];
      		if(c[j]>=10) 
      		{
      			c[j]%=10;
      			a[j+1]++;
      		}
      	}
      	c[0]=j;
      	if(c[j+1]>0) c[0]++;
      	for(int i=c[0]; i>=1; i--) 
      	{
      		if(x==false&&c[i]==0) 
      		continue;
      		x=true;
      		cout<<c[i];
      	}
      	if(x==false) 
      	cout<<0;
      	printf("\n");
      	return 0;
      }
      

      管理员大大求过QAQ

      彩蛋

      文言版

      #及充窦融之女孙侍中垒兴矣。
      用命名为帝喾咨d
      甲戌,武军二千人[71]以五十吏二千人,吏二千人五十余年;
      &lt;
      甲戌,封府库二千二千余家,帝喾二千余家;
      &lt
      {
      更老女喜刑名。帝喾寿梦有子;
      更典帝喾嘉伯喈①,吾寿梦有子②;
      更典帝喾嘉伯喈。
      帝喾八月壬戌岂可怒哉!帝喾聿怀金玉,为帝喾次妃。
      [47]陈民典诰。
      [47]民义并行。
      猫一窦秋开二水中;
      [88]唐赛明之后[82]--][57]
      猫一窦秋开二水中;
      [88]唐广明年金涂海伯萧][57]-
      刘保好心,好梦回漠北;无如之何。
      {
      [88]刘宇深,[88];
      吾乃龌龊。
      {
      [88]徐卢=;
      [88]唐武爱吾;
      }
      }
      [88]
      [88]聚野草花,疏刑部伍胥靡];
      了窦融一窦通漾场;
      {
      若孝明旦唱为帝喾做成何人,
      引兵久之。
      蜥蜴_然;
      功名吟泽,无片云;
      }
      若(旦旦唱)
      co mán)42 30。
      乐则灵惨凄部(lya n.
      还。
      }
      
      • @ 2023-7-29 12:46:32

        a,b106a,b\le 10^6,用传统数据类型不能存吗?为什么用高精度加?

      • @ 2023-10-3 19:26:30

        @ 他炫技呗,别管这种人

    • -2
      @ 2022-11-22 16:02:23
      #include <bits/stdc++.h>
      using namespace std;int a,b;int main(){cin>>a>>b;cout<<a+b<<endl;return 0;}
      
      • -2
        @ 2022-11-20 18:23:45

        非常简单的一道题,输出a+b的和即可。

        代码:

        #include<cstdio>//C语言风格输入输出头文件
        int main(){ //主函数
            int a,b;//定义变量
            scanf("%d%d",&a,&b);//输入a和b
            printf("%d",a+b);//输出a+b
            return 0; //返回值
        }
        
        • -2
          @ 2022-6-19 11:30:22

          补充一个julialang题解

          a=parse(Int, readuntil(stdin, ' '))
          b=parse(Int, readline())
          print(a+b)
          
          • -2
            @ 2022-5-29 14:48:53

            好吧,同志们,我们就从这一题开始,向着大牛的路进发。 任何一个伟大的思想,都有一个微不足道的开始。

            #include<bits/stdc++.h>//万能头文件
            using namespace std;//使用标准命名空间
            int a,b;//定义整型变量a、b,也就是参与运算的两个数
            int main(){//主函数,程序在这里运行
                cin>>a>>b;//标准输入
                cout<<a+b;//标准输出
                return 0;//返回值,主函数的返回值必须是0
            }
            
            • -2
              @ 2022-5-19 20:26:54
              #include<iostream>//建议用iostream
              using namespace std;//使用标准命名空间
              int main(){//主函数
              	int a,b;
              	cin>>a>>b;
              	cout<<a+b;
              	return 0;
              }
              
              • -2
                @ 2022-5-8 20:16:04

                入门题,每个OIer入坑必做题

                不废话,直接上代码!

                C++:

                ```
                #include<iostream>
                using namespace std;
                int main(){
                    int a,b;//定义变量
                    cin>>a>>b;//输入
                    cout<<a+b<<endl;//计算,输出
                }
                ```
                

                python3:

                # python3 要使用split函数,因为输入是一行两个数字,spilt函数可以把两个数字读取而不读取空格
                a=input().split() 
                print(int(a0])+int(a[1]))
                
                • -2
                  @ 2022-5-7 10:36:51

                  这题很简单,输入 a 和 b,然后输出他们的和即可。

                  #include <bits/stdc++.h>
                  using namespace std;
                  
                  int main()
                  {
                          int a,b;
                          cin >> a >> b;
                          cout << a + b;
                  	
                  	
                  
                  	return 0;
                  }
                  
                  • -2
                    @ 2022-3-22 12:54:54

                    这道题目就是输出 a+b 的和就OK了! AC Code:

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

                    注:我是新手,请多多请教!

                    • @ 2022-6-8 9:14:48

                      我不理解这种题解为什么会有人踩

                    • @ 2022-7-25 16:29:54

                      @因为没解释!

                  • -2
                    @ 2022-2-27 21:35:30
                    #include <cstdio>
                    using namespace std;
                    int n, m;
                    int main() {
                        scanf("%d %d", &n, &m);
                        printf("%d", n + m);
                        return 0;
                    }
                    
                    • -2
                      @ 2021-12-11 15:59:56

                      一份十分简洁的 py3 代码:

                      print(sum(map(int,input().split())))
                      

                      分析

                      map(int,input().split())
                      

                      这句话将第一行输入数据读入,然后将其按空格分裂成 list。map 函数将这个 list 中的每个元素变成 int。

                      print(sum(map(int,input().split())))
                      

                      接着,sum 函数求出了这个 list 内所有数的和,即 a+b。print 将其输出。

                      • -2
                        @ 2021-6-1 16:10:19

                        这是一道很简单的入门题。
                        可以直接写出代码:

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

                        感谢您的阅读。

                        • -2
                          @ 2021-4-19 6:47:31
                          
                          import java.util.Scanner;
                          public class Main {   
                              private static Scanner s;
                              public static void main(String[] args) {
                                  s = new Scanner(System.in); 
                                  int a = s.nextInt();
                                  int b = s.nextInt();
                                  System.out.println(a + b); 
                              } 
                          }
                          
                          • -3
                            @ 2024-1-28 13:57:08

                            a

                            • -3
                              @ 2023-8-31 18:44:38

                              这里估计大部分都是写了c++有一定基础的,那么我就用链表实现a+b问题吧

                              #include <iostream>
                              struct ListNode
                              {
                                  int val;
                                  ListNode *next;
                                  ListNode(int x) : val(x), next(nullptr) {}
                              };
                              ListNode *addTwoNumbers(ListNode *l1, ListNode *l2)
                              {
                                  ListNode *dummy = new ListNode(0);
                                  ListNode *current = dummy;
                                  int carry = 0;
                                  while (l1 || l2 || carry)
                                  {
                                      int sum = carry;
                                      if (l1)
                                      {
                                          sum += l1->val;
                                          l1 = l1->next;
                                      }
                                      if (l2)
                                      {
                                          sum += l2->val;
                                          l2 = l2->next;
                                      }
                                      carry = sum / 10;
                                      sum = sum % 10;
                                      current->next = new ListNode(sum);
                                      current = current->next;
                                  }
                                  return dummy->next;
                              }
                              ListNode *createLinkedList(int arr[], int n)
                              {
                                  if (n == 0)
                                  {
                                      return nullptr;
                                  }
                                  ListNode *head = new ListNode(arr[0]);
                                  ListNode *current = head;
                                  for (int i = 1; i < n; i++)
                                  {
                                      current->next = new ListNode(arr[i]);
                                      current = current->next;
                                  }
                                  return head;
                              }
                              void printLinkedList(ListNode *head)
                              {
                                  ListNode *current = head;
                                  while (current)
                                  {
                                      std::cout << current->val << " ";
                                      current = current->next;
                                  }
                                  std::cout << std::endl;
                              }
                              int main()
                              {
                                  int arr1[1];
                                  int arr2[1];
                                  std::cin >> arr1[0];
                                  std::cin >> arr2[0];
                                  int n1 = sizeof(arr1) / sizeof(arr1[0]);
                                  int n2 = sizeof(arr2) / sizeof(arr2[0]);
                                  ListNode *l1 = createLinkedList(arr1, n1);
                                  ListNode *l2 = createLinkedList(arr2, n2);
                                  ListNode *sum = addTwoNumbers(l1, l2);
                                  printLinkedList(sum);
                                  return 0;
                              }
                              
                              • -3
                                @ 2023-8-2 16:18:31

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

                                • -3
                                  @ 2023-8-2 16:17:15

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

                                  • -3
                                    @ 2023-3-27 20:33:37
                                    #include<bits/stdc++.h>
                                    using namespace std;
                                    int main()
                                    {
                                    	ios::sync_with_stdio(false);
                                    	long long a,b;
                                    	cin>>a>>b;
                                    	cout<<a+b;
                                    	return 0;
                                    }
                                    

                                    信息

                                    ID
                                    56
                                    时间
                                    1000ms
                                    内存
                                    1024MiB
                                    难度
                                    1
                                    标签
                                    递交数
                                    8392
                                    已通过
                                    3776
                                    上传者