1323 条题解
-
-1㸚茻㠭㗊 LV 4 @ 2019-09-11 20:20:15
//最简做法 #include<cstdio> int main() { int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); return 0; }
-
-12019-08-31 15:03:02@
#include <bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<a+b; return 0; }
-
-12019-08-27 18:04:02@
Python3
cpp
a,b = map(int,input().split())
print(a + b)
-
-12019-08-19 15:15:03@
任何一个伟大的思想,都有一个微不足道的开始。
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin>>a>>b; cout<<a+b; return 0; } >当快读来帮忙: ```cpp #include<bits/stdc++.h> using namespace std; int a,b; int read() { int r=0,f=1; char c=getchar(); while((c<'0'||c>'9')&&c!='-') c=getchar(); if(c=='-') f=-1,c=getchar(); while(c<='9'&&c>='0') r=r*10+c-'0',c=getchar(); return r*f; } int main() { a=read(); b=read(); printf("%d",a+b); return 0; }
之后还有高精度:
#include <bits/stdc++.h> #define ri register int #define maxn 510 using namespace std; string s1,s2; int a[maxn],b[maxn],c[maxn],la,lb,len; int main() { getline(cin,s1); getline(cin,s2); if(s1[0]==48&&s2[0]==48){ printf("0"); return 0; } la=s1.size(); lb=s2.size(); for(ri i=0;i<la;i++) a[la-i-1]=s1[i]-48; for(ri i=0;i<lb;i++) b[lb-i-1]=s2[i]-48; len=max(la,lb); for(ri i=0; i<len; i++) { c[i]+=a[i]+b[i]; c[i+1]=c[i]/10; c[i]%=10; } len++; while(c[len]==0) len--; for(ri i=len; i>=0; i--) printf("%d",c[i]); return 0; }
-
-12019-08-16 14:01:12@
#include<bits/stdc++.h>//万能头文件
using namespace std;
int a,b,c;//定义
int main()//主程序
{
scanf("%d%d",&a,&b);//比cin快的输入
c=a+b;//幼儿园加减法
printf("%d",c);//比cout快的输出
return 0;//返回并退出
}//over -
-12019-07-21 17:27:29@
利用
c++
中类(class
)的构造函数以及析构函数(Constructor & Destructor
)输入输出。(真的不会超时,一共就*12ms*)
```cpp
#include<bits/stdc++.h>
using namespace std;
class AplusBproblem{
public:
AplusBproblem(){
cin>>x>>y;
}
~AplusBproblem(){
cout<<x+y<<endl;
}
private:
int x,y;
};
int main(){
AplusBproblem beginner;
return 0;
}**跟大家唠嗑两句,此题看似简易,实则内涵丰富,其解法更是犇上加犇,迄今为止已有不下```1<<5```种解法。大家一定要灵活运用知识,思维要开放。**
-
-12019-07-15 18:26:05@
张测试
测试下 md
-
-12019-07-12 22:32:35@
基础题(入门)
#include <iostream> using namespace std; int main() { int a, b, c; cin>>a>>b; c=a+b; cout<<c<<endl; return 0; }
类似题:洛谷P3954
-
-12019-07-11 18:25:30@
我的第一篇题解
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a + b << endl; }
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a + b << endl; }
-
-12019-07-11 18:19:50@
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a + b << endl; }
-
-12019-07-10 11:47:38@
废话少说,高精,上!!!(C++)
#include<bits/stdc++.h>//万能头 using namespace std; int a1[1000],a2[1000],c[1000]; int main(){ string s1,s2; int l1,l2,lc; cin>>s1>>s2;//输入 l1=s1.size(); l2=s2.size(); lc=max(l1,l2); for(int i=0;i<=l1-1;i++){ a1[i]=s1[l1-i-1]-'0'; } for(int i=0;i<=l2-1;i++){ a2[i]=s2[l2-i-1]-'0'; } for(int i=0;i<=lc-1;i++){ c[i]+=a1[i]+a2[i]; if(c[i]>=10){ c[i]%=10; c[i+1]++; } } if(c[lc]!=0) lc++; while(c[lc-1]==0 && lc!=1) lc--; //防止最高位为零 for(int i=lc-1;i>=0;i--) cout<<c[i]; //输出 return 0; }
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; }
正解:
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<a+b; return 0; }
-
-12019-07-10 11:46:55@
废话少说,高精,上!!!(C++)
#include<bits/stdc++.h>//万能头 using namespace std; int a1[1000],a2[1000],c[1000]; int main(){ string s1,s2; int l1,l2,lc; cin>>s1>>s2;//输入 l1=s1.size(); l2=s2.size(); lc=max(l1,l2); for(int i=0;i<=l1-1;i++){ a1[i]=s1[l1-i-1]-'0'; } for(int i=0;i<=l2-1;i++){ a2[i]=s2[l2-i-1]-'0'; } for(int i=0;i<=lc-1;i++){ c[i]+=a1[i]+a2[i]; if(c[i]>=10){ c[i]%=10; c[i+1]++; } } if(c[lc]!=0) lc++; while(c[lc-1]==0 && lc!=1) lc--; //防止最高位为零 for(int i=lc-1;i>=0;i--) cout<<c[i]; //输出 return 0; }
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; }
正解:
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<a+b; return 0; }
-
-12019-07-10 11:46:08@
废话少说,高精,上!!!(C++)
#include<bits/stdc++.h>//万能头 using namespace std; int a1[1000],a2[1000],c[1000]; int main(){ string s1,s2; int l1,l2,lc; cin>>s1>>s2;//输入 l1=s1.size(); l2=s2.size(); lc=max(l1,l2); for(int i=0;i<=l1-1;i++){ a1[i]=s1[l1-i-1]-'0'; } for(int i=0;i<=l2-1;i++){ a2[i]=s2[l2-i-1]-'0'; } for(int i=0;i<=lc-1;i++){ c[i]+=a1[i]+a2[i]; if(c[i]>=10){ c[i]%=10; c[i+1]++; } } if(c[lc]!=0) lc++; while(c[lc-1]==0 && lc!=1) lc--; //防止最高位为零 for(int i=lc-1;i>=0;i--) cout<<c[i]; //输出 return 0; }
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; }
正解:
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<a+b; return 0; }
-
-12019-07-09 09:23:27@
splay.
#include <bits/stdc++.h> #define ll long long #define N 100000 using namespace std; int sz[N], rev[N], tag[N], sum[N], ch[N][2], fa[N], val[N]; int n, m, rt, x; void push_up(int x){ sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1; sum[x] = sum[ch[x][1]] + sum[ch[x][0]] + val[x]; } void push_down(int x){ if(rev[x]){ swap(ch[x][0], ch[x][1]); if(ch[x][1]) rev[ch[x][1]] ^= 1; if(ch[x][0]) rev[ch[x][0]] ^= 1; rev[x] = 0; } if(tag[x]){ if(ch[x][1]) tag[ch[x][1]] += tag[x], sum[ch[x][1]] += tag[x]; if(ch[x][0]) tag[ch[x][0]] += tag[x], sum[ch[x][0]] += tag[x]; tag[x] = 0; } } void rotate(int x, int &k){ int y = fa[x], z = fa[fa[x]]; int kind = ch[y][1] == x; if(y == k) k = x; else ch[z][ch[z][1]==y] = x; fa[x] = z; fa[y] = x; fa[ch[x][!kind]] = y; ch[y][kind] = ch[x][!kind]; ch[x][!kind] = y; push_up(y); push_up(x); } void splay(int x, int &k){ while(x != k){ int y = fa[x], z = fa[fa[x]]; if(y != k) if(ch[y][1] == x ^ ch[z][1] == y) rotate(x, k); else rotate(y, k); rotate(x, k); } } int kth(int x, int k){ push_down(x); int r = sz[ch[x][0]]+1; if(k == r) return x; if(k < r) return kth(ch[x][0], k); else return kth(ch[x][1], k-r); } void split(int l, int r){ int x = kth(rt, l), y = kth(rt, r+2); splay(x, rt); splay(y, ch[rt][1]); } void rever(int l, int r){ split(l, r); rev[ch[ch[rt][1]][0]] ^= 1; } void add(int l, int r, int v){ split(l, r); tag[ch[ch[rt][1]][0]] += v; val[ch[ch[rt][1]][0]] += v; push_up(ch[ch[rt][1]][0]); } int build(int l, int r, int f){ if(l > r) return 0; if(l == r){ fa[l] = f; sz[l] = 1; return l; } int mid = l + r >> 1; ch[mid][0] = build(l, mid-1, mid); ch[mid][1] = build(mid+1, r, mid); fa[mid] = f; push_up(mid); return mid; } int asksum(int l, int r){ split(l, r); return sum[ch[ch[rt][1]][0]]; } int main(){ //总共两个数 n = 2; rt = build(1, n+2, 0);//建树 for(int i = 1; i <= n; i++){ scanf("%d", &x); add(i, i, x);//区间加 } rever(1, n);//区间翻转 printf("%d\n", asksum(1, n));//区间求和 return 0; }
-
-12019-06-27 12:54:21@
#include<bits/stdc++.h> using namespace std; const int TT=10000; inline int read(){ int ret=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();} while(isdigit(ch)) ret=ret*10+ch-'0',ch=getchar(); return ret; } struct xx{ int a[3005],len; xx(){len=0;memset(a,0,sizeof a);} xx(int x){ len=0;memset(a,0,sizeof a); do{a[++len]=x%TT,x/=TT;}while(x); } xx operator+(const xx b){ xx c;c.len=max(len,b.len); for(int i=1;i<=c.len;i++){ c.a[i]+=a[i]+b.a[i]; c.a[i+1]+=c.a[i]/TT; c.a[i]%=TT; } if(c.a[c.len+1]) c.len++; return c; } void print(){ printf("%d",a[len]); for(int i=len-1;i>=1;i--)printf("%04d",a[i]); printf("\n"); } }a,b,c; int main(){ a=read(),b=read(); c=a+b; c.print(); return 0; }
-
-12019-06-22 01:00:12@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#include <ctime>
#include <string>
#include <cstring>
using namespace std;
const int N=405;
struct Edge {
int v,w;
};
vector<Edge> edge[N*N];
int n;
int dis[N*N];
bool vis[N*N];
struct cmp {
bool operator()(int a,int b) {
return dis[a]>dis[b];
}
};
int Dijkstra(int start,int end)
{
priority_queue<int,vector<int>,cmp> dijQue;
memset(dis,-1,sizeof(dis));
memset(vis,0,sizeof(vis));
dijQue.push(start);
dis[start]=0;
while(!dijQue.empty()) {
int u=dijQue.top();
dijQue.pop();
vis[u]=0;
if(u==end)
break;
for(int i=0; i<edge[u].size(); i++) {
int v=edge[u][i].v;
if(dis[v]==-1 || dis[v]>dis[u]+edge[u][i].w) {
dis[v]=dis[u]+edge[u][i].w;
if(!vis[v]) {
vis[v]=true;
dijQue.push(v);
}
}
}
}
return dis[end];
}
int main()
{
int a,b;
scanf("%d%d",&a,&b);
Edge Qpush;Qpush.v=1;
Qpush.w=a;
edge[0].push_back(Qpush);Qpush.v=2;
Qpush.w=b;
edge[1].push_back(Qpush);printf("%d",Dijkstra(0,2));
return 0;
} -
-12019-05-26 16:06:36@
来发字典树
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; struct node{ int str[26]; int sum; }s[1000]; char str1[100]; int t=0,tot=0,ss=0; bool f1; void built() { t=0; for(int i=0;i<strlen(str1);i++) { if(str1[i]=='-'){ f1=true;continue; } if(!s[t].str[str1[i]-'0']) s[t].str[str1[i]-'0']=++tot; t=s[t].str[str1[i]-'0']; s[t].sum=str1[i]-'0'; } } int query() { int t=0;int s1=0; for(int i=0;i<strlen(str1);i++) { if(str1[i]=='-') continue; if(!s[t].str[str1[i]-'0']) return s1; t=s[t].str[str1[i]-'0']; s1=s1*10+s[t].sum; } return s1; } int main() { for(int i=1;i<=2;i++) { f1=false; scanf("%s",str1); built(); if(f1) ss-=query(); else ss+=query(); } printf("%d",ss); return 0; }
-
-12019-03-25 22:13:11@
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
} -
-12019-03-25 20:00:53@
#include<cstdio> int main(){ int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); return 0; }
-
-12019-03-25 19:59:39@
#include<cstdio> int a[-1u]; int main(){ int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); return 0; }
信息
- ID
- 1000
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 74450
- 已通过
- 28496
- 通过率
- 38%
- 被复制
- 223