搬运洛谷博客中……qaq
以下是a+b问题各种解法的汇总(我真无聊),有些是我自己写的,有些是别人写的。
注意:此篇博客我标了原创,但有些内容是转载的
普通
#include <iostream>
using namespace std;
int main()
{
cin>>a>>b;
cout<<a+b;
return 0;
}
读入优化
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int read()
{
int out=0,fh=1;
char cc=getchar();
if (cc=='-')
fh=-1;
while (cc>'9'||cc<'0')
cc=getchar();
while (cc>='0'&&cc<='9')
{
out=out*10+cc-'0';
cc=getchar();
}
return out*fh;
}
void write(int x)
{
if (x==0)
{
putchar('0');
return;
}
int num = 0;
char c[15];
while (x)
c[ ++num ] = (x%10)+48,x /= 10;
while (num)
putchar(c[ num-- ]);
putchar(' ');
}
int main(){
write(read()+read());
return 0;
}
SPFA
#include<cstdio>
#include<iostream>
using namespace std;
int n,m,a,b,op,head[200009],next[200009],dis[200009],len[200009],v[200009],l,r,team[200009],pd[100009],u,v1,e;
int lt(int x,int y,int z)
{
op++;
v[op]=y;
next[op]=head[x],head[x]=op,len[op]=z;
}
int SPFA(int s,int f)
{
for (int i=1;i<=200009;i++)
dis[i]=999999999;
l=0,r=1,team[1]=s,pd[s]=1,dis[s]=0;
while (l!=r)
{
l=(l+