ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

模板合集

2021-10-20 20:01:58  阅读:95  来源: 互联网

标签:ch int pass push dis 合集 模板 define


目录

码头

Click
/*
I he so I pass, I pass because I he.
Not he Can't pass, Not pass because Not he.
----------------
Author: cnyz
----------------
Looking! The blitz loop this planet to search way.
Only my RAILGUN can shoot it. 今すぐ
*/
#include<bits/stdc++.h>
using namespace std;

typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define Online 1
#define enter pc('\n')
#define space pc(' ')
const int MAXL=1<<22;
char i_str[MAXL],o_str[MAXL],*i_s,*i_t;
int o_t;
inline char gc() {
    if(!Online) return getchar();
    if(i_s==i_t) {
        i_s=i_str;
        i_t=i_s+fread(i_str,1,MAXL,stdin);
        return i_s==i_t?EOF:*i_s++;
    } else return *i_s++;
}
inline void gs(char *s) {
    *s=gc();
    while(*s==' '||*s=='\n')*s=gc();
    while(*s!=' '&&*s!='\n')*++s=gc();
    *s='\0';
}
inline int read() {
    int x=0,f=0;
    char ch=gc();
    for(; ch<'0'||ch>'9'; ch=gc())
        if(ch=='-')f=1;
    for(; ch>='0'&&ch<='9'; ch=gc())
        x=(x<<1)+(x<<3)+(ch^48);
    return f?~x+1:x;
}
inline double readdb() {
    double x=0;
    int f=0;
    char ch=gc();
    for(; ch<'0'||ch>'9'; ch=gc())
        if(ch=='-')f=1;
    for(; ch>='0'&&ch<='9'; ch=gc())
        x=x*10+(ch^48);
    if(ch=='.') {
        ch=gc();
        for(double y=0.1;ch>='0'&&ch<='9';ch=gc(),y*=0.1)
            x=x+y*(ch^48);
    }
    return f?-x:x;
}
#define WDNMD fwrite(o_str,1,o_t,stdout),o_t=0
inline void pc(char x) {
    if(!Online) {
        putchar(x);
        return;
    }
    o_str[o_t++]=x;
    if(o_t==MAXL)WDNMD;
}
inline void write(int x) {
    if(x<0)x=-x,pc('-');
    if(x>9)write(x/10);
    pc(x%10^48);
}
inline void chkmax(int &x,int y) {
    if(x<y) x=y;
}
inline void chkmin(int &x,int y) {
    if(x>y) x=y;
}

SPFA

Click
void spfa() {
    queue<int> q;
    q.push(1);
    for(int i=2;i<=n;i++) dis[i]=1e18;
    dis[1]=0;
    while(q.size()) {
        int u=q.front();
        q.pop();
        for(auto i:G[u]) {
            int v=i.fi,d=i.se;
            if(dis[v]>dis[u]+d) dis[v]=dis[u]+d,q.push(v);
        }
    }
}

Dijkstra

Click
void dij() {
    q.push(mp(0,1));
    for(int i=2;i<=n;i++) dis[i]=1e18;
    dis[1]=0;
    while(q.size()) {
        int u=q.top().se;q.pop();
        if(vis[u]) continue;
        vis[u]=1;
        for(auto i:G[u]) {
            int v=i.fi,d=i.se;
            if(dis[v]>dis[u]+d) {
                dis[v]=dis[u]+d;
                q.push(mp(-dis[v],v));
            }
        }
    }
}

Prim

Click
void Prim() {
    for(int i=1;i<=n;i++) dis[i]=1e18;
    dis[1]=0;
    for(int i=1;i<=n;i++) {
        ll mi=1e18;int id=0;
        for(int j=1;j<=n;j++)
            if(!vis[j]&&mi>=dis[j]) id=j,mi=dis[j];
        vis[id]=1;ans+=dis[id];
        for(auto v:G[id])
            if(!vis[v.fi])
                if(v.se<=dis[v.fi])
                    dis[v.fi]=v.se;
    }
}

标签:ch,int,pass,push,dis,合集,模板,define
来源: https://www.cnblogs.com/lajiccf/p/15430294.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有