• [补]2020nowcoder牛客多校第一场H


    复习keyword 最大流 最小割 ISAP 费用流 SPFA

     题意:最小费用,q个询问,每次将所有边容量设为u/v,源点流量为1(或许流不完)

    试图先瞎流个小数来着,Thor告知会t就内心毫无波动了。试图考虑扩成整数,但据说q看起来不管怎么写都会t,看起来在思考但实际上没有任何想法.jpg(我理解是最差VE*q)

    总之扩大v倍后,流量v,容量u,费用v倍

    #include<iostream>
    #include<cstdio>
    #include<queue>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    
    typedef long long LL;
    const LL INF=1e18;
    
    struct edge{
        int t,nex;
        LL c,w,fl;
    }e[103];
    int head[53],ecnt,vis[53],pre[53],co;
    LL dis[53], mi[53], unit[103];
    vector<LL>con[53];
    
    LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
    struct mcf{ int s,t,n; void init(int ss, int tt){ s=ss,t=tt; n=t; for(int i=0;i<=n;i++)con[i].clear(); ecnt=0; co=0; } void adde(int a,int b,LL c,LL w,LL fl){ e[ecnt].nex=head[a]; e[ecnt].t=b; e[ecnt].c=c; e[ecnt].w=w; e[ecnt].fl=fl; head[a]=ecnt++; } void add(int a, int b, LL c, LL w,LL fl ){ adde(a,b,c,w,fl); adde(b,a,0,-w,fl); con[a].push_back(ecnt-2); con[b].push_back(ecnt-1); } bool spfa(int s, int t, LL& fl, LL& ct){ queue<int>p; for(int i=0;i<=n;i++){ dis[i]=INF; vis[i]=0; } dis[s]=0,vis[s]=1; pre[s]=0; mi[s]=INF; p.push(s); while(!p.empty()){ int u=p.front(); p.pop(); for(int i=0; i<con[u].size() ;i++){ int eg=con[u][i]; int v=e[eg].t; if(e[eg].c>e[eg].fl&&dis[v]>dis[u]+e[eg].w){ dis[v]=dis[u]+e[eg].w; pre[u]=eg; mi[v]=min(mi[u],e[eg].c-e[eg].fl); if(!vis[v]){ vis[v]=1; p.push(v); } } } vis[u]=0; } if(dis[t]==INF)return 0; fl+=mi[t]; ct+=dis[t]*mi[t]; int now=s; while(now!=t){ e[pre[now]].fl+=mi[t]; e[pre[now]^1].fl-=mi[t]; now=e[pre[now]].t; } return 1; } LL mc(){ LL fl=0,ct=0; while(spfa(s,t,fl,ct))unit[++co]=dis[t]; return fl; } }net; int main() { int n,m,q,u,v; while(~scanf("%d%d",&n,&m)){ net.init(1,n); for(int i=1;i<=m;i++){ LL w; scanf("%d%d%lld",&u,&v,&w); net.add(u, v, 1, w,0); } net.mc(); scanf("%d",&q); while(q--){ scanf("%d%d",&u,&v); LL top=0,bom=v; for(int i=1;i<=co;i++){ if(v>u){ v-=u; top+=unit[i]*u; } else{ top+=unit[i]*v; v=0;
                break; } }
    if(v){cout<<"NaN"<<endl;continue;} LL g=gcd(top,bom); top/=g; bom/=g; cout<<top<<"/"<<bom<<endl; } } return 0; }

    敲了半天板子最后删了一堆。本来手写了个que,结果test1就炸了,虽然后来发现不是这里的事但懒得再改了_(:з」∠)_

    还搞了些TLE/RE出来,总之是些没有经验可以吸收的错误

    啊不,有一个TLE很妙,一开始SPFA入队出队里面每次扫全图,改成了过一遍以当前点为顶点的边(?)我觉得红小豆没太记住,下次看估计就忘光了

    没有比学了跟没学似的更痛苦的事了

    仍然不清楚是什么让喜爱的事情变得痛苦

    和众人的热爱比起来确实一文不值

    总是对别人无罪推定就会无法宽恕自己

    拥有可能性却不去争取是很恶劣的事吧

    就算不争取大家才会幸福起来?

    尽管不想用这个blog了但想了想还是发在这里了,原来的账号也好好用起来吧

    发之前的瞎扯upd:第三场虽然排名比前两场要糟糕,但是状态要好多了(仅仅是从愉快感的方面说)。会很怕想少,于是就想太多,愈发不敢去做什么尝试——罚时会影响排名、思路的错误诱导会耗费队友心力还影响最终成绩、结果不好的话又会引起更深的无力感——因为是兴趣型选手(被这么评价了也确实自我认可)所以压力是最没用的东西了吧,明明想的是没有成果也可以只要全部结束后得到“一起快乐地比赛了”的结果就行了,是自私的想法然而又没有按照自己这样的想法去抉择,矛盾着得过且过。总是这样啊,想要摸鱼地度过一个阶段却很快发现自己扛着鱼冲上了前线(笑死)。如果睡眠紊乱尽快好起来,blog也会加快一点写的(还愿?)

  • 相关阅读:
    Locust学习笔记3——模拟登录案例(非加密)
    Locust学习笔记2——环境搭建与基本用法
    Locust学习笔记1——性能测试工具选择
    Pytest学习笔记7——接口自动化测试框架实战附源码(开荒篇)
    Pytest学习笔记6——自定义用例顺序
    Pytest学习笔记5——Allure测试报告用例详细描述
    Pytest学习笔记4——测试步骤
    Python 批量插入100万级数据到Excel文件(简洁版)
    [Java] SpringBoot
    [bug] Springboot JPA使用Sort排序时的问题
  • 原文地址:https://www.cnblogs.com/non-/p/13342226.html
Copyright © 2020-2023  润新知