32ms!!!

P1001 A+B Problem

qinyiyang2012 @ 2024-08-13 16:43:19

新手这样写简单易懂

#include<bits/stdc++.h>
using namespace std;
#define dIO_USE_BUFFER 
struct IO{
#ifdef dIO_USE_BUFFER
    const static int BUFSIZE=1<<20;
    char ibuf[BUFSIZE], obuf[BUFSIZE], *p1, *p2, *pp;
    inline int getchar(){return(p1 == p2&&(p2=(p1=ibuf)+fread(ibuf,1,BUFSIZE,stdin),p1==p2)?EOF:*p1++);}
    inline int putchar(char x){return((pp-obuf==BUFSIZE&&(fwrite(obuf,1,BUFSIZE,stdout),pp=obuf)),*pp=x,pp++),x;}
    IO(){p1=p2=ibuf,pp=obuf;}
    ~IO(){fwrite(obuf,1,pp-obuf,stdout),pp=obuf,fflush(stdout);}
#else
    int (*getchar)()=&::getchar,(*putchar)(int)=&::putchar;
    inline IO &flush(){return fflush(stdout),*this;}
#endif
    template<typename Tp,typename enable_if<is_integral<Tp>::value>::type * =nullptr>
    inline void read(Tp &s){
        int f=1,ch=getchar();s=0;
        while(!isdigit(ch))f=(ch=='-'?-1:1),ch=getchar();
        while(ch == '0')ch = getchar();
        while(isdigit(ch))s=s*10+(ch^48),ch=getchar();
        s*=f;
    }
    template<typename Tp,typename enable_if<is_integral<Tp>::value>::type * =nullptr>
    inline void write(Tp x){
        if(x<0)putchar('-'),x=-x;
        static char sta[41];
        int top=0;
        do sta[top++]=x%10^48,x/=10;while(x);
        while(top)putchar(sta[--top]);
    }
    template<typename Tp>
    inline void writeln(const Tp &x){write(x);putchar('\n');}
    template<typename Tp>
    inline void writeSp(const Tp &x){write(x);putchar(' ');}
}io;
int main(){
    int a,b;
    io.read(a),io.read(b);
    io.write(a+b);
    return 0;
}

by imzoeg @ 2024-08-13 16:45:26

6(新手易懂)


by CAO654321 @ 2024-08-13 16:45:47

999


by Lijiangjun4 @ 2024-08-13 16:55:57

6


by hushuoyan @ 2024-08-13 20:34:21

新手易懂程序:(真的)

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

int a,b;

int main(){
  cin >> a >> b;
  cout << a + b;
}

by chenzhishuo2012 @ 2024-08-14 09:34:44

新手易懂程序:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
int read(void){
    int x=0;int w=1;char ch=0;
    while(!isdigit(ch)){if(ch=='-')w=-1;if(ch=='+')w=1;ch=getchar();}
    while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return w*x;
}
void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int Left(int a){return a*2;}
int Right(int a){return a*2+1;}
int i,j,k,m,n,a[1000001],ans[1000001],Lazy[1000001],lazy[1000001];
void PushUp(int now){
    ans[now]=(ans[Left(now)]+ans[Right(now)]);
}
void Build(int now,int l,int r){
    if(l==r){ans[now]=a[l];return;}
    int mid=(l+r)/2;
    Build(Left(now),l,mid);
    Build(Right(now),mid+1,r);
    PushUp(now);
}
void Function(int now,int l,int r,int Add){
    Lazy[now]+=Add;
    ans[now]+=Add*(r-l+1);
}
void PushDown(int now,int l,int r){
    int mid=(l+r)/2;
    Function(Left(now),l,mid,Lazy[now]);
    Function(Right(now),mid+1,r,Lazy[now]);
    Lazy[now]=0;
}
void function(int now,int l,int r,int Add){
    Lazy[now]*=Add;
    lazy[now]*=Add;
    ans[now]*=Add;
}
void Push_Down(int now,int l,int r){
    int mid=(l+r)/2;
    function(Left(now),l,mid,lazy[now]);
    function(Right(now),mid+1,r,lazy[now]);
    lazy[now]=1;
}
void Data(int NowL,int NowR,int l,int r,int now,int Add){
    if(NowL<=l&&NowR>=r){
        ans[now]+=Add*(r-l+1);
        Lazy[now]+=Add;
        return;
    }
    Push_Down(now,l,r);
    PushDown(now,l,r);
    int mid=(l+r)/2;
    if(NowL<=mid)Data(NowL,NowR,l,mid,Left(now),Add);
    if(NowR>mid)Data(NowL,NowR,mid+1,r,Right(now),Add);
    PushUp(now);
}
void data(int NowL,int NowR,int l,int r,int now,int Add){
    if(NowL<=l&&NowR>=r){
        ans[now]*=Add;
        Lazy[now]*=Add;
        lazy[now]*=Add;
        return;
    }
    Push_Down(now,l,r);
    PushDown(now,l,r);
    int mid=(l+r)/2;
    if(NowL<=mid)data(NowL,NowR,l,mid,Left(now),Add);
    if(NowR>mid)data(NowL,NowR,mid+1,r,Right(now),Add);
    PushUp(now);
}
int Query(int NowL,int NowR,int l,int r,int now){
    int Return=0;
    if(NowL<=l&&NowR>=r)return ans[now];
    int mid=(l+r)/2;
    Push_Down(now,l,r);
    PushDown(now,l,r);
    if(NowL<=mid)Return+=Query(NowL,NowR,l,mid,Left(now));
    if(NowR>mid)Return+=Query(NowL,NowR,mid+1,r,Right(now));
    return Return;
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    n=2;
    int A=read(),B=read();
    Build(1,1,n);
    for(i=1;i<=n*4;i++)lazy[i]=1;
    int Gcd=gcd(A,B);
    Data(1,1,1,n,1,A/Gcd);
    Data(2,2,1,n,1,B/Gcd);
    data(1,2,1,n,1,Gcd);
    write(Query(1,2,1,n,1));
}

by zichang2011steven @ 2024-08-18 08:50:13

(新手易懂)


|