P1001_a+b问题算法汇总

本文汇总了洛谷上的a+b问题的各种解法,包括普通方法、读入优化、SPFA、Floyd算法、压位高精度、线段树、最小生成树和LCT等。适合于提升算法理解与实践。
摘要由CSDN通过智能技术生成

搬运洛谷博客中……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+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值