1328 条题解
-
15
Wylker LV 8 @ 2018-05-01 16:13:03
告诉你们什么叫做暴力的题解。
#include<bits/stdc++.h> #define gou int main() #define li { #define guo int a,b; #define jia cin>>a>>b; #define sheng cout<<a+b; #define si return 0; #define yi } using namespace std; gou li guo jia sheng si yi
-
122021-08-30 11:48:08@
本题直接用
int
就能过。
完整代码:#include<iostream> //引入 iostream 头文件 using namespace std; //使用 std 命名空间 int main(){ //主函数,程序从这里开始 int a,b; //定义两个变量,一个叫 a ,一个叫 b cin>>a>>b; //输入 cout<<a+b; //输出他们的和 return 0; //主函数应返回 0 }
讲解:
-iostream
头文件也叫输入输出流,是 C++ 特有的头文件,用来输入和输出。
-std
命名空间是 C++ 的标准命名空间,输入输出就定义在这里面。
-int main()
函数是程序的开始,一个程序必须有他。
-int a,b
是定义了两个int
型变量,\(a\) 和 \(b\)。
-cin>>a>>b
是在输入 \(a\) 和 \(b\)。
-cout<<a+b
是在输出 \(a+b\)。
-return 0
是int main()
函数的返回值,这个返回值必须是 \(0\) ,不然会 RE。管理员大大求通过
看在我写得这么认真的情况下,就给我点个赞吧 -
52023-10-07 23:22:21@
/******************************************************** 备注: ********************************************************/ #include <iostream> #include <iomanip> #include <cmath> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; #define LL long long #define MAXM 3010 #define MAXN 3010 const int N =1e5+10; const int INF =0x3f3f3f3f; int main () { int a,b; cin>>a>>b; cout<<a+b; return 0; }
-
22024-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; }
-
22022-05-08 18:14:23@
基础语法
//头文件 #include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #include <cmath> //命名空间 using namespace std; //主函数 int main() { int x, y; //定义x,y //int类型,用"%d"输出 scanf("%d%d", &x, &y); //输入x,y printf("%d", x + y); //输出x + y return 0; }
-
12025-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; }
-
12024-10-24 14:24:10@
#include<iostream> using namespace std; int main() { int a,b; cin >> a >> b; cout << a + b; return 0; }
-
12024-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
-
12024-03-21 20:45:30@
main(a,b){scanf("%d%d",&a,&b);printf("%d",a+b);}
-
12024-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; }
-
12023-06-15 22:11:05@
超级大模拟:
#include <iostream>
#include <cmath>
using namespace std;
int fu=1,f=1,a,b,c=0;
int main()
{
cin>>a>>b;
if(a<0&&b>0)fu=2;
if(a>0&&b<0)fu=3;
if(a<0&&b<0)f=-1;
if(a==0){cout<<b;return 0;}
if(b==0){cout<<a;return 0;}
a=abs(a);
b=abs(b);
if(a>b&&fu==3)f=1;
if(b>a&&fu==3)f=-1;
if(b>a&&fu==2)f=1;
if(b<a&&fu==2)f=-1;
if(fu==1)c=a+b;
if(fu>1)c=max(a,b)-min(a,b);
c*=f;
cout<<c;
return 0;
} -
12023-05-26 16:53:32@
居然没看到2行代码,那我就来写一个
#include<bits/stdc++.h> using namespace std;int main(){int a,b;cin>>a>>b;a += b;cout<<a<<endl;return 0;}
原代码
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; a += b; cout<<a<<endl; return 0; }
-
02025-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; }
-
02025-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
-
02025-01-23 21:02:19@
什么是一行?它(Python 3)说……
python
print(sum(map(int, input().split()))
-
02024-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; }
-
02024-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;
} -
02024-08-24 10:07:41@
非常简单的新手入门题
```cpp
#include <iostream>
//头文件
using namespace std;
//命名空间
int main()
{
int a,b;//定义
cin>>a>>b;//输入
cout<<a+b<<endl;//输出
} -
02024-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()就可以过 -
02024-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 ,程序结束 }
点个赞再走呗🥺
信息
- ID
- 1000
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 74801
- 已通过
- 28644
- 通过率
- 38%
- 被复制
- 250