1338 条题解
-
0
suning LV 9 @ 2006-02-10 18:41:59
var c:word;
a,b:longint;
begin
c:=a+b;
writeln(c);
end. -
0@ 2006-02-08 14:24:58
var c : word;
a, b : longint;
begin
c:=a+b;
writeln(c);
end. -
-1@ 2026-08-20 16:13:19
当我是Python程序员:
代码:
a=int(input(Please input number a:))
b=int(input(Please input nember b:))
print(a+b)应该能过吧...
-
-1@ 2026-08-13 19:30:57
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
} -
-1@ 2026-07-22 14:25:27
考虑使用线段树。
把 \(a,b\) 看成一个长度为 \(2\) 的区间,先
build\((a)\),然后update\((b)\),最后输出query\((a,b)\)。非常的水,很好的线段树题目,适合于初学者。
#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@ 2026-05-22 20:47:00
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b;
} -
-1@ 2026-03-04 21:15:32
输入 \(a\) 和 \(b\) 再输出 \(a + b\) 就行了喵。
-
-1@ 2025-12-06 12:44:23
这题是简单的\(A+B\)问题,常常作为系统测试题目使用,C++主流写法有两类:
- ### 主程序写法
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<a+b; }#include<bits/stdc++.h> using namespace std; int main(){ int a,b; scanf("%d%d",&a,&b); printf("%d",a+b); }注:这里的第二种写法更偏向于C风格,但在需要快速读入你又不会快读的时候,这种写法能体现出略微的优势。
- ###
asm写法
#include<iostream> using namespace std; int main(){ int a,b,sum; cin>>a>>b; asm volatile( "movl %1,%%eax\n\t" "addl %2,%%eax\n\t" "movl %%eax,%0" :"=r"(sum) :"r"(a),"r"(b) :"eax" ); cout<<sum; } -
-1@ 2025-11-01 15:43:26
#include<bits/stdc++.h> using namespace std; #define int long long #define ull unsigned int #define N 1048576 int memory[N],pos; string code[N]={ }; string readStr(int x,int y) // 从 code[x][y] 开始读取一个字符串, 读到空格为止 { pos=y; string ret=""; int len=code[x].length(); while(pos<len && code[x][pos]==' ') { ++pos; } while(pos<len && code[x][pos]!=' ') { ret=ret+code[x][pos++]; } return ret; } int readInt(int x,int y) // 从 code[x][y] 开始读取一个整数, 读到非数字为止 { pos=y; int ret=0, len=code[x].length(); bool f=0; while(pos<len && !isdigit(code[x][pos])) { if(code[x][pos]=='-') { f=1; } ++pos; } while(pos<len && isdigit(code[x][pos])) { ret=(ret<<3)+(ret<<1)+(code[x][pos++]^48); } return f?-ret:ret; } signed main() { for(int i=0;;i=(i+1)%N) { string op=readStr(i,0); if(op=="input") { int x=readInt(i,pos); cin>>memory[x]; } else if(op=="output") { string mode=readStr(i,pos); if(mode=="int") { int x=readInt(i,pos); cout<<memory[x]; } else if(mode=="char") { int x=readInt(i,pos); cout<<char(memory[x]%128); } else { cout<<"\n\nError: Invalid Code at i = "<<i<<"\n\n"; break; } } else if(op=="write") { int x=readInt(i,pos), y=readInt(i,pos); memory[x]=y; } else if(op=="copy") { int x=readInt(i,pos), y=readInt(i,pos); memory[y]=memory[x]; } else if(op=="calc") // and or not xor add sub mul div mod { string mode=readStr(i,pos); int x=readInt(i,pos), y=readInt(i,pos), z=(mode=="not" ? 0 : readInt(i,pos)); x=memory[x], y=memory[y]; if(mode=="and") { memory[z]=x&y; } else if(mode=="or") { memory[z]=x|y; } else if(mode=="not") { memory[y]=~x; } else if(mode=="xor") { memory[z]=x^y; } else if(mode=="add") { memory[z]=x+y; } else if(mode=="sub") { memory[z]=x-y; } else if(mode=="mul") { memory[z]=x*y; } else if(mode=="div") { if(y==0) { cout<<"\n\nError: Division by Zero\n\n"; break; } memory[z]=x/y; } else if(mode=="mod") { memory[z]=x%y; } else { cout<<"\n\nError: Invalid Code at i = "<<i<<"\n\n"; break; } } else if(op=="goto") { int x=readInt(i,pos); i=x-1; } else if(op=="if") // < > == <= >= != { string mode=readStr(i,pos); int x=readInt(i,pos), y=readInt(i,pos), z=readInt(i,pos); x=memory[x], y=memory[y]; if(mode=="<") { if(x<y) { i=z-1; } } else if(mode==">") { if(x>y) { i=z-1; } } else if(mode=="==") { if(x==y) { i=z-1; } } else if(mode=="<=") { if(x<=y) { i=z-1; } } else if(mode==">=") { if(x>=y) { i=z-1; } } else if(mode=="!=") { if(x!=y) { i=z-1; } } else { cout<<"\n\nError: Invalid Code at i = "<<i<<"\n\n"; break; } } else if(op=="++") { int x=readInt(i,pos); memory[x]++; } else if(op=="--") { int x=readInt(i,pos); memory[x]--; } else if(op=="exit") { break; } else { cout<<"\n\nError: Invalid Code at i = "<<i<<"\n\n"; break; } } return 0; } -
-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'; } -
-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-28 09:36:20
想要更简单做法请移步至其他题解。
本题有一种好想但码量较大的做法,可以直接将问题转化为网络流模型,跑一边最大流就可以了。为防止 TLE 特地学习了一遍预流推进。
#include<bits/stdc++.h> using namespace std; const int N=2e4+5,M=2e5+5,inf=0x3f3f3f3f; int n,s,t,tot; int v[M<<1],w[M<<1],first[N],nxt[M<<1]; int h[N],e[N],gap[N<<1],inq[N]; struct cmp { inline bool operator()(int a,int b) const { return h[a]<h[b]; } }; queue<int> Q; priority_queue<int,vector<int>,cmp> pQ; inline void add_edge(int from,int to,int flow) { tot+=2; v[tot+1]=from;v[tot]=to;w[tot]=flow;w[tot+1]=0; nxt[tot]=first[from];first[from]=tot; nxt[tot+1]=first[to];first[to]=tot+1; return; } inline bool bfs() { int now; int go; memset(h+1,0x3f,sizeof(int)*n); h[t]=0;Q.push(t); while(!Q.empty()) { now=Q.front();Q.pop(); for(go=first[now];go;go=nxt[go]) if(w[go^1]&&h[v[go]]>h[now]+1) h[v[go]]=h[now]+1,Q.push(v[go]); } return h[s]!=inf; } inline void push(int now) { int d; int go; for(go=first[now];go;go=nxt[go]) if(w[go]&&h[v[go]]+1==h[now]) { d=min(e[now],w[go]); w[go]-=d;w[go^1]+=d;e[now]-=d;e[v[go]]+=d; if(v[go]!=s&&v[go]!=t&&!inq[v[go]]) pQ.push(v[go]),inq[v[go]]=1; if(!e[now]) break; } return; } inline void relabel(int now) { int go; h[now]=inf; for(go=first[now];go;go=nxt[go]) if(w[go]&&h[v[go]]+1<h[now]) h[now]=h[v[go]]+1; return; } inline int hlpp() { int now,d; register int i,go; if(!bfs()) return 0; h[s]=n; memset(gap,0,sizeof(int)*(n<<1)); for(i=1;i<=n;i++) if(h[i]<inf) ++gap[h[i]]; for(go=first[s];go;go=nxt[go]) if(d=w[go]) { w[go]-=d;w[go^1]+=d;e[s]-=d;e[v[go]]+=d; if(v[go]!=s&&v[go]!=t&&!inq[v[go]]) pQ.push(v[go]),inq[v[go]]=1; } while(!pQ.empty()) { inq[now=pQ.top()]=0;pQ.pop();push(now); if(e[now]) { if(!--gap[h[now]]) for(i=1;i<=n;i++) if(i!=s&&i!=t&&h[i]>h[now]&&h[i]<n+1) h[i]=n+1; relabel(now);++gap[h[now]]; pQ.push(now);inq[now]=1; } } return e[t]; } int m; signed main() { int x,y; cin>>x>>y; n=4,m=4,s=1,t=4; add_edge(1,2,x); add_edge(1,3,y); add_edge(2,4,10000000); add_edge(3,4,10000000); printf("%d\n",hlpp()); 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;
}
信息
- ID
- 1000
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 75671
- 已通过
- 28884
- 通过率
- 38%
- 被复制
- 279