文章

3

粉丝

260

获赞

4

访问

31.8k

头像
A+Bproblem (c++)<----抓换的思想
推荐阅读
P1000 计算机考研机试入门题
发布于2019年12月14日 11:44
阅读数 14.5k

这道题是我在本站上A的第一道题,那我们直接开始吧:
首先,我们要用到转换的思想,既然这道题跟代数有关,那我们便可以把它转换为图论,如图:

又因为在题目的数据中并没有负数,那么,显然这个问题就转化为了求源点S到汇点T的最大流,接着就是模板就行了

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int getint() {
    int ret=0,flag=1;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-')flag=-1;
        c=getchar();
    }
    while(c<='9'&&c>='0') {
        ret=(ret<<3)+(ret<<1)+c-'0';
        c=getchar();
    }
    return ret*flag;
}
int n,m;
int S,T;
int cnt,head[100005];
struct edge {
    int ne,v,w,pair;
} e[2000005];
void add(int u,int v,int p) {
    cnt++;
    e[cnt].v=v;
    e[cnt].w=p;
    e[cnt].pair=cnt+1;
    e[cnt].ne=head[u];
    head[u]=cnt;

//    cnt++;
//    e[cnt].v=u;
//    e[cnt].w=0;
//    e[cnt].pair=cnt-1;
//    e[cnt].ne=head[v];
//    head[v]=cnt;
}
int dis[100005],gap[100005];
int DFS(int x,int maxf) {
    if(x==T)return maxf;
    int ret=0;
    for(int i=head[x]; i...
登录查看完整内容


登录后发布评论

7 条评论
Julianne
2024年4月20日 13:34

真是疯了

赞(0)
爱在西元前
2024年4月6日 09:15

crying

赞(0)
snake
2024年3月21日 09:17

yes

赞(0)
莫小七
2020年2月21日 09:35

大佬花式解题,给跪了!!!

赞(0)
kurui98
2020年1月21日 09:38

疯了????

赞(0)
江淮左
2019年12月30日 09:59

请问模版是在哪里总结的

赞(0)
admin SVIP
2019年12月14日 15:00

我给你82分,剩下18分拆成666给你

赞(0)