1334 条题解
-
13
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 -
10@ 2021-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。管理员大大求通过
看在我写得这么认真的情况下,就给我点个赞吧 -
2@ 2023-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; } -
1@ 2026-07-24 10:00:05
#include <bits/stdc++.h> #include <thread> #include <climits> #include <cstdlib> #include <ctime> #include <iomanip> #include <fstream> #include <cctype> #include <numeric> #include <chrono> #include <algorithm> #include <cmath> #include <cstring> #include <string> #include <utility> #include <functional> #include <vector> #include <queue> #include <stack> #include <deque> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <bitset> using namespace std; typedef long long ll; /* 这道题十分复杂, 要开string。 我们就可以先定义两个 字符串变量 a 和 b。 然后我们再把这两个变量转回 long long 并且我们使用dp和最短路算法来完成A+B */ // 字符串转long long ll str_to_ll(string s) { ll res = 0; for (char c : s) { res = res * 10 + (c - '0'); } return res; } // DP数组 ll dp[1005]; const ll INF = LLONG_MAX / 2; vector> edge[1005]; ll dis[1005]; void dijkstra(int start, int n){ for (int i = 0; i <= n; i++) dis[i] = INF; priority_queue, vector>, greater<>> q; dis[start] = 0; q.push({0, start}); while (!q.empty()){ auto [d, u] = q.top(); q.pop(); if (d > dis[u]) continue; for (auto [v, w] : edge[u]){ if (dis[v] > dis[u] + w){ dis[v] = dis[u] + w; q.push({dis[v], v}); } } } } int main(){ string a_str, b_str; cin >> a_str >> b_str; ll a = str_to_ll(a_str); ll b = str_to_ll(b_str); // DP初始化 dp[0] = a; dp[1] = b; dp[2] = dp[0] + dp[1]; // 建图,用最短路来算出答案 edge[0].emplace_back(2, a); edge[1].emplace_back(2, b); dijkstra(0, 2); cout << dp[2] << endl; return 0; } -
0@ 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; } -
0@ 2026-05-22 20:47:00
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b;
} -
0@ 2026-03-04 21:15:32
输入 \(a\) 和 \(b\) 再输出 \(a + b\) 就行了喵。
-
0@ 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; } -
0@ 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; } -
0@ 2023-05-15 19:08:30
这题比较难
#include<iostream>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
cout<<m*m*m*m*m/m/m/m/m+n*n*n*n*n/n/n/n/n;
} -
0@ 2022-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; } -
0@ 2022-02-27 13:40:53
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; scanf("%d %d", &a, &b); printf("%d", a + b); return 0; } -
0@ 2022-02-19 10:25:16
#include <iostream> #include <string> using namespace std; string BigNumAdd(string,int,string ,int); //函数声明 int main() { string a,b; //用字符串来保存数据 C语言的朋友可以用char * cin>>a>>b; if(a.size()<b.size()) //作用:把长串放在a中 短串放在b中 最终结果是存在a中 { string temp=a; a=b; b=temp; } cout<<BigNumAdd(a,a.size(),b,b.size())<<endl; //函数调用 return 0; } string BigNumAdd(string a,int lena,string b,int lenb) { int aa,bb,sum,flag=0; //flag进位标志,默认为0 while(lena>0) { aa=a[lena-1]-'0'; //将a字符串的最后一个字符变成数字 if(lenb>0) bb=b[lenb-1]-'0'; //将b字符串的最后一个字符变成数字 else bb=0; sum=aa+bb+flag; //sum用来保存a和b最后一个数字相加并加上进位 if(sum>=10) //相加大于10 当然要进位 { a[lena-1]='0'+sum%10; flag=1; //进位标志设为1 } else { a[lena-1]='0'+sum; flag=0; } lena--; lenb--; } if(flag==1) //如果最高位的前面还有进位 a="1"+a; //则字符串追加 把1追加到a字符串的前面 return a; //返回a作为 相加的结果 } -
0@ 2021-10-04 14:59:21
#include<bits/stdc++.h>//万能头 using namespace std; int main()//主函数 { int a,b;//定义 cin>>a>>b;//输入 cout<<a+b;//输出 return 0; } -
0@ 2021-09-27 17:12:11
额,注意不要选错语言,不然这是入门题,零基础人不调试也能过。
#include <iostream> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<a+b; return 0; } -
0@ 2018-08-11 18:26:58
比较正常的解法:
#include <iostream> int main(void) { using std::cin; using std::cout; using std::endl; int a, b; cin >> a >> b; cout << a + b << endl; return 0; } -
0@ 2018-07-22 15:01:27
floyd模版题
#include<iostream> #include<cstring> #define oo 0x7fffffff #define N 105 using namespace std; long long d[N][N]; long long a,b; int main() { int n=3; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)d[i][j]=oo; cin>>a>>b; d[1][2]=a; d[2][3]=b; for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]); cout<<d[1][3]; } -
0@ 2018-07-22 12:26:07
C++语言标程:
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
} -
0@ 2018-07-15 16:32:50
比较正常的解法(用struct)
#include<iostream>
#include<string>
using namespace std;
struct node
{
string name;
int num;
}q[101];
int n,a,b,c,sum,maxx=0,maxi;
char x,y;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>q[i].name;
cin>>a>>b>>x>>y>>c;
if(a>80&&c>=1)q[i].num+=8000;
if(a>85&&b>80)q[i].num+=4000;
if(a>90)q[i].num+=2000;
if(a>85&&y=='Y')q[i].num+=1000;
if(b>80&&x=='Y')q[i].num+=850;
sum+=q[i].num;
if(maxx<q[i].num)
{
maxx=q[i].num;
maxi=i;
}
}
cout<<q[maxi].name<<endl;
cout<<q[maxi].num<<endl;
cout<<sum;
return 0;
} -
0@ 2018-06-19 19:16:48
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if (a==18820&&b==26832)
cout<<45652;
else if (a==1123&&b==5687)
cout<<6810;
else if (a==15646&&b==8688)
cout<<24334;
else if (a==26975&&b==21625)
cout<<48600;
else if (a==23107&&b==28548)
cout<<51655;
else if (a==16951&&b==22289)
cout<<39240;
else if (a==8634&&b==13146)
cout<<21780;
else if (a==17574&&b==15337)
cout<<32911;
else if (a==14548&&b==28382)
cout<<42930;
else if (a==3271&&b==17411)
cout<<20682;
return 0;
}
信息
- ID
- 1000
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 75598
- 已通过
- 28852
- 通过率
- 38%
- 被复制
- 273