1330 条题解
-
14
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。管理员大大求通过
看在我写得这么认真的情况下,就给我点个赞吧 -
3@ 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@ 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@ 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@ 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;
} -
0@ 2018-06-18 09:30:47
vijos对这道题太仁慈了,数据范围这么小,还没有负数。
我的这个递归算法放到luogu或者openjudge会MLE+TLE。
您现在看到的是史上第一个超时的a+b problem,
卡测评机的新方法,你没有玩过的全新版本。#include <iostream> using namespace std; long long add(long long a,long long b){ if(a == 0 && b == 0) return 0; else if(a == 0 || b == 0){ if(a == 0 && b > 0) return add(a,b-1)+1; else if(a > 0 && b == 0) return add(a-1,b)+1; else if(a < 0 && b == 0) return add(a+1,b)-1; else if(a == 0 && b < 0) return add(a,b+1)-1; } else if(a > 0 && b > 0) return add(a-1,b-1)+2; else if(a > 0 && b < 0) return add(a-1,b+1); else if(a < 0 && b > 0) return add(a+1,b-1); else if(a < 0 && b < 0) return add(a+1,b+1)-2; } int main(){ long long a,b; cin>>a>>b; cout<<add(a,b)<<endl; return 0; } -
0@ 2018-06-18 09:09:19
递归版。
#include <iostream> using namespace std; int add(int a,int b){ if(a == 0 && b == 0) return 0; else if(a == 0 || b == 0){ if(a == 0 && b != 0) return add(a,b-1)+1; else if(a != 0 && b == 0) return add(a-1,b)+1; } else if(a != 0 && b != 0) return add(a-1,b-1)+2; } int main(){ int a,b; cin>>a>>b; cout<<add(a,b)<<endl; return 0; } -
0@ 2018-06-07 19:58:55
#include<cstdio>
int main()
{
long long a,b,c;scanf("%lld%lld%lld",&a,&b,&c);printf("%lld\n",a+b+c);return 0;
} //很难吗? -
0@ 2018-06-07 19:58:14
#include<cstdio>
int main()
{
long long a,b,c;scanf("%lld%lld%lld",&a,&b,&c);printf("%lld\n",a+b+c);return 0;
}
信息
- ID
- 1000
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 75247
- 已通过
- 28778
- 通过率
- 38%
- 被复制
- 265