题解

1332 条题解

  • -1
    @ 2025-07-14 22:02:27

    这题可以运用高精度加法来解决

    #include<bits/stdc++.h>
    using namespace std;
    
    string s1,s2;
    int a[1005],b[1005],c[1005];
    int lena,lenb; 
    
    int main(){
        cin>>s1>>s2;
        lena=s1.length();
        lenb=s2.length();
        for(int i=0;i<lena;i++)
            a[i]=s1[lena-1-i]-'0';
        for(int i=0;i<lenb;i++)
            b[i]=s2[lenb-1-i]-'0';
        int lenn=max(lena,lenb);
        for(int i=0;i<lenn;i++){
            c[i]+=a[i]+b[i];
            c[i+1]=c[i]/10;
            c[i]%=10;
        }
        lenn++;
        while(lenn>1 && c[lenn-1]==0)
            lenn--;
        for(int i=lenn-1;i>=0;i--)
            cout<<c[i];
        return 0;
    }
    
  • -1
    @ 2025-07-12 22:12:47

    直接上AC代码(*这道题是最水的题了*(划掉)):

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

    另外,欢迎参加洛谷www.luogu.com.cn

  • -1
    @ 2025-07-09 21:43:18

    这是一道非常水的~~线段树~~题目,我们可以建立一个大小为 \(3\) 的 \(w\) 数组,\(w_0\) 不用管,\(w_1\) 存 \(a\) 的值,\(w_2\) 暂时先存 \(0\)(因为在后来的更新函数把 \(2\sim2\) 的范围改为 \(b\),相当于给 \(0+b\)),建树(范围 \(1\sim2\)),更新(范围 \(2\sim2\)),最后输出查询 \(1\sim2\) 范围的和。

    #include<bits/stdc++.h>
    #define lc p<<1
    #define rc p<<1|1
    using namespace std;
    struct node{
        int l,r,sum,add;
    }tr[3*4+5];
    int w[3];
    void pushup(int p){
        tr[p].sum=tr[lc].sum+tr[rc].sum;
    }
    void pushdown(int p){
        if(tr[p].add){
            tr[lc].sum+=(tr[lc].r-tr[lc].l+1)*tr[p].add;
            tr[rc].sum+=(tr[rc].r-tr[rc].l+1)*tr[p].add;
            tr[lc].add+=tr[p].add;
            tr[rc].add+=tr[p].add;
            tr[p].add=0;
        }
    }
    void build(int p,int l,int r){
        tr[p]={l,r,w[l],0};
        if(l==r)return ;
        int mid=l+r>>1;
        build(lc,1,mid);
        build(rc,mid+1,r);
        pushup(p);
    }
    void update(int p,int l,int r,int k){
        if(l<=tr[p].l&&tr[p].r<=r){
            tr[p].sum+=(tr[p].r-tr[p].l+1)*k;
            tr[p].add+=k;
            return ;
        }
        int mid=tr[p].l+tr[p].r>>1;
        pushdown(p);
        if(l<=mid)update(lc,l,r,k);
        if(r>mid)update(rc,l,r,k);
        pushup(p);
    }
    int query(int p,int l,int r){
        if(l<=tr[p].l&&tr[p].r<=r)return tr[p].sum;
        int mid=tr[p].l+tr[p].r>>1;
        pushdown(p);
        int sum=0;
        if(l<=mid)sum+=query(lc,l,r);
        if(r>mid)sum+=query(rc,l,r);
        return sum;
    }
    int main(){
        cin>>w[1];
        w[2]=0;
        build(1,1,2);
        int b;
        cin>>b;
        update(1,2,2,b);
        cout<<query(1,1,2);
        return 0;
    }
    
  • -1
    @ 2025-04-10 20:26:57
    #include<bits/stdc++.h>
    using namespace std;
    struct sb{
        int a,b;
    };
    int main(){
        sb n;
        cin>>n.a>>n.b;
        cout<<n.a+n.b<<'\n';
    }
    
    • @ 2025-07-09 21:46:23

      结构体类型名不文明,差评 \(+\) 举报

  • -1
    @ 2025-01-23 21:02:19

    什么是一行?它(Python 3)说……
    python
    print(sum(map(int, input().split()))

  • -1
    @ 2024-12-10 22:28:18

    一道很好的 树状数组 题。

    #include <iostream>
    #include <string>
    #include <cstdio>
    using namespace std;
    
    struct Array {
        int *arr;
        int lowbit(int x) {
            return x & -x;
        }
        int getsum(int x) { //计算[1,x]区间中数列和
            int ret=0;
            while(x>0) {
                ret+=arr[x];
                x=x-lowbit(x);
            }
            return ret;
        }
        
        void plus(int x, int v) { //把第x个元素增加v
            while(x <= (int)sizeof(arr)) {
                arr[x]=arr[x]+v;
                x=x+lowbit(x);
            }
        }
        
        Array() {}
        Array(int length, int arr[]) {
            this->arr=new int[length+1];
            for(int i=1; i<=length; i++) this->arr[i]=0;
            for(int i=1; i<=length; i++) plus(i, arr[i-1]);
        }
        ~Array()=default;
    };
    
    int main() {
        Array a;
        int arr[2];
        scanf("%d%d", &arr[0], &arr[1]);
        a=Array(2, arr);
        printf("%d\n", a.getsum(2));
        return 0;
    }
    
  • -1
    @ 2024-12-09 16:51:14

    我有两篇题解:
    给新手小白的:

    #include<iostream>
    int main(){
        int a,b;
        scanf("%d %d",&a,&b);
        printf("%d",a+b);
        return 0;
    }
    

    这是给大佬的:

    #include<iostream>
    #include<string>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    const int N = 1005;
    struct bign
    {
        int len,s[N];
        bign()  {  memset(s,0,sizeof(s));  len=1;  }
        bign(int num)  {  *this=num; }
        bign(char *num) { *this=num; }
        bign operator =(int num)
        {
            char c[N];
            sprintf(c,"%d",num);
            *this=c;
            return *this;
        }
        bign operator =(const char *num)
        {
            len=strlen(num);
            for (int i=0;i<len;i++) s[i]=num[len-1-i]-'0';
            return *this;
        }
        string str()
        {
            string res="";
            for (int i=0;i<len;i++) res=(char)(s[i]+'0')+res;
            return res;
        }
        void clean()
        {
            while (len>1&&!s[len-1]) len--;
        }
        bign operator +(const bign &b)
        {
            bign c;    
            c.len=0;
            for (int i=0,g=0;g||i<len||i<b.len;i++)
            {
                int x=g;
                if (i<len) x+=s[i];
                if (i<b.len) x+=b.s[i];
                c.s[c.len++]=x%10;
                g=x/10;
            }
            return c;
        }
        bign operator -(const bign &b)
        {
            bign c;
            c.len=0;
            int x;     
            for (int i=0,g=0;i<len;i++)
            {
                x=s[i]-g;
                if (i<b.len) x-=b.s[i];
                if (x>=0) g=0;
                else{          
                    x+=10;
                    g=1;
                };
                c.s[c.len++]=x;
            }
            c.clean();
            return c;
        }
        bign operator *(const bign &b)
        {
            bign c;
            c.len=len+b.len;
            for (int i=0;i<len;i++) for (int j=0;j<b.len;j++) c.s[i+j]+=s[i]*b.s[j];
            for (int i=0;i<c.len-1;i++) { c.s[i+1]+=c.s[i]/10; c.s[i]%=10; }
            c.clean();
            return c;  
        }
        bool operator <(const bign &b)
        {
            if (len!=b.len) return len<b.len;
            for (int i=len-1;i>=0;i--)
                 if (s[i]!=b.s[i]) return s[i]<b.s[i];
            return false;
        }
        bign operator +=(const bign &b)
        {
            *this=*this+b;
            return *this;
        }
        bign operator -=(const bign &b)
        {
            *this=*this-b;
            return *this;
        }  
    };
    istream& operator >>(istream &in,bign &x)
    {
      string s;
      in>>s;
      x=s.c_str();
      return in;
    }
    ostream& operator <<(ostream &out,bign &x)
    {
        out<<x.str();
        return out;
    }
    int main(){
        bign a,b,c;
        ios::sync_with_stdio(false);
        cin>>a>>b;
        c=a+b;
        cout<<c<<endl;
        return 0;
    }
    

    希望这篇题解有助于大家!

  • -1
    @ 2024-11-09 16:36:24

    水题中的水题中的水题

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        long long a,b;
        cin>>a>>b;
        cout<<a+b;
    
        return 0;
    }
    
  • -1
    @ 2024-10-24 14:24:10
    #include<iostream>
    using namespace std;
    int main() {
        int a,b;
        cin >> a >> b;
        cout << a + b;
        return 0;
    }
    
  • -1
    @ 2024-10-04 09:25:02

    A + B问题实在是太难了,不过用LCT还是能解出来的,代码如下
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    struct node
    {
    int data,rev,sum;
    node *son[2],*pre;
    bool judge();
    bool isroot();
    void pushdown();
    void update();
    void setson(node *child,int lr);
    }lct[233];
    int top,a,b;
    node *getnew(int x)
    {
    node *now=lct+ ++top;
    now->data=x;
    now->pre=now->son[1]=now->son[0]=lct;
    now->sum=0;
    now->rev=0;
    return now;
    }
    bool node::judge(){return pre->son[1]==this;}
    bool node::isroot()
    {
    if(pre==lct)return true;
    return !(pre->son[1]==this||pre->son[0]==this);
    }
    void node::pushdown()
    {
    if(this==lct||!rev)return;
    swap(son[0],son[1]);
    son[0]->rev^=1;
    son[1]->rev^=1;
    rev=0;
    }
    void node::update(){sum=son[1]->sum+son[0]->sum+data;}
    void node::setson(node *child,int lr)
    {
    this->pushdown();
    child->pre=this;
    son[lr]=child;
    this->update();
    }
    void rotate(node *now)
    {
    node *father=now->pre,*grandfa=father->pre;
    if(!father->isroot()) grandfa->pushdown();
    father->pushdown();now->pushdown();
    int lr=now->judge();
    father->setson(now->son[lr^1],lr);
    if(father->isroot()) now->pre=grandfa;
    else grandfa->setson(now,father->judge());
    now->setson(father,lr^1);
    father->update();now->update();
    if(grandfa!=lct) grandfa->update();
    }
    void splay(node *now)
    {
    if(now->isroot())return;
    for(;!now->isroot();rotate(now))
    if(!now->pre->isroot())
    now->judge()==now->pre->judge()?rotate(now->pre):rotate(now);
    }
    node *access(node *now)
    {
    node *last=lct;
    for(;now!=lct;last=now,now=now->pre)
    {
    splay(now);
    now->setson(last,1);
    }
    return last;
    }
    void changeroot(node *now)
    {
    access(now)->rev^=1;
    splay(now);
    }
    void connect(node *x,node *y)
    {
    changeroot(x);
    x->pre=y;
    access(x);
    }
    void cut(node *x,node *y)
    {
    changeroot(x);
    access(y);
    splay(x);
    x->pushdown();
    x->son[1]=y->pre=lct;
    x->update();
    }
    int query(node *x,node *y)
    {
    changeroot(x);
    node *now=access(y);
    return now->sum;
    }
    int main()
    {
    scanf("%d%d",&a,&b);
    node *A=getnew(a);
    node *B=getnew(b);
    //连边 Link
    connect(A,B);
    //断边 Cut
    cut(A,B);
    //再连边orz Link again
    connect(A,B);
    printf("%d\n",query(A,B));
    return 0;
    }

  • -1
    @ 2024-08-30 19:03:01

    #include<bits/stdc++.h>
    using namespace std;
    long long a[1000],b[1000],c[1000];
    int main(){
    string s,s1;
    cin>>s>>s1;
    for(int i=0;i<s.size();i++){
    a[i]=s[s.size()-1-i]-'0';
    }
    for(int j=0;j<s1.size();j++){
    b[j]=s1[s1.size()-1-j]-'0';
    }
    int l;
    if(s.size()>s1.size()){
    l=s.size();
    }else{
    l=s1.size();
    }
    for(int i=0;i<l;i++){
    c[i]=a[i]+b[i];
    }
    for(int i=0;i<l;i++){
    if(c[i]>=10){
    c[i]=c[i]-10;
    c[i+1]++;
    }
    }
    if(c[l]!=0){
    l++;
    }
    for(int i=l-1;i>=0;i--){
    cout<<c[i];
    }
    return 0;
    }

  • -1
    @ 2024-08-27 19:43:03

    C++基本格式

    #include <iostream>
    using namespace std;
    int main(void) {
        return 0;
    }
    

    在第3行后面添加代码。

    int a, b;//定义两个变量a和b
    cin >> a >> b;//输入a和b
    cout << a + b;//计算a + b并把结果输出
    

    点个赞再走呗,跪谢!ヾ(≧▽≦*)o

  • -1
    @ 2024-08-24 10:07:41

    非常简单的新手入门题
    ```cpp
    #include <iostream>
    //头文件
    using namespace std;
    //命名空间
    int main()
    {
    int a,b;//定义
    cin>>a>>b;//输入
    cout<<a+b<<endl;//输出
    }

  • -1
    @ 2024-08-13 16:28:00

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    int x,y;
    cin>>x>>y;
    if(0<=x,y<=32767){
    cout<<x+y;
    }else{
    cout<<"NO";
    }
    return 0;
    }
    此题非常的简单
    直接一个if()就可以过

  • -1
    @ 2024-07-09 13:56:08

    特别简单

    #include<bits/stdc++.h>//万能头文件
    using namespace std;//使用一个标准的命名空间
    int main(){
        int a,b;//定义变量a,b
        cin>>a>>b;//手动输入a和b
        cout<<a+b<<endl;//输出a+b的值
        return 0;//返回0 ,程序结束
    }
    
    

    点个赞再走呗🥺

  • -1
    @ 2024-06-01 16:05:45
    #include<bits/stdc++.h>
    int a,b;
    int main(){
        scanf("%d%d",&a,&b);
        printf("%d",a+b);
        return 0;
    }
        
    
  • -1
    @ 2024-05-26 11:34:40

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

  • -1
    @ 2024-05-12 16:21:12

    可以尝试用时间复杂度为\( O(a^a+b^b*2) \)的算法去做(doge

  • -1
    @ 2024-03-21 20:45:30
    main(a,b){scanf("%d%d",&a,&b);printf("%d",a+b);}
    
    
  • -1
    @ 2024-03-21 20:42:40
    
    #include<bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    template<class T> void read(T &x) {
        x = 0; T f = 1; char c = getchar();
        for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
        for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - 48; x *= f;
    }
    template<class T> void write(T x) {
        if (x > 9) write(x / 10); putchar(x % 10 + 48);
    }
    template<class T> void print(T x, char ed = '\n') {
        if (x < 0) putchar('-'), x = -x; write(x), putchar(ed);
    }//抄来的快读快写
    int main(){
        ll a,b;
        read(a);
        read(b);
        print(a+b);
        return 0;
    }
    
    

信息

ID
1000
难度
9
分类
(无)
标签
(无)
递交数
75452
已通过
28829
通过率
38%
被复制
272