zoukankan      html  css  js  c++  java
  • hdu5988 Coding Contest

    首先这是个费用流,用log转乘法为加法,外加模板的修改,需加eps

    下面是废话,最好别看
    闲来无事(鼓起勇气)写这篇博客
    这是个自带影像回访的题目
    青岛的炼铜之旅,大学的acm生涯就这样结束了。或许还会刷刷题目,但是也再也没有证明自己的机会和心气。
    回想大学的这段旅程。
    大一下接触acm,为进集训队拼命刷题,因为基础差在暑假的集训后没有能够去区域赛。郁闷的大二上加寒假没有刷题。大二下因为特别的机会得以和老队友参加省赛,差一名得金。从大二下开始每天从早上到晚上刷题。本以为可以报大腿在之后获得银牌甚至金牌。但是暑假被分到其他队。大三上拼命刷,最后得到两铜也算是我的预期(预期要打铁的)。
    过去感觉的自己跟小伙伴有那么多差距,本以为可以赶上他们。似乎以前他们说的一些解法我都听不懂,现在我可以听懂,甚至提出自己的解法。
    但是,
    但是只是靠近,永远无法追上他们了。
    acm也算从小的一个梦想,小时候没有机缘参加信息学竞赛,羡慕并且好奇。这个隐藏的梦想因为acm的相遇而被实现。

    我也不能说这段经历有点悲伤吧。我确实不够努力。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define begin Begin
    #define end End
    #define next nxt
    
    const int N = 108, M = 50000;
    const int INF = 1e9;
    const double eps = 1e-7;
    int q[1000000];
    struct Node{
        int u, v, cap;
        double cost;
        int next;
    }edge[M];//有向图,u到v的容量,费用
    int tot;
    int head[N], pre[N], path[N];
    double dis[N];
    bool inq[N];
    
    void init(){
        tot = 0;
        memset(head, -1, sizeof(head));
    }
    
    void addedge(int u, int v, int cap, double cost){
        edge[tot].u = u;
        edge[tot].v = v;
        edge[tot].cap = cap;
        edge[tot].cost = cost;
        edge[tot].next = head[u];
        head[u] = tot++;
        edge[tot].u = v;
        edge[tot].v = u;
        edge[tot].cap = 0;
        edge[tot].cost = -cost;
        edge[tot].next = head[v];
        head[v] = tot++;
    }
    
    bool SPFA(int st, int des){
        memset(inq, 0, sizeof(inq));
        fill(dis, dis + des + 2, INF);
        memset(pre, -1, sizeof(pre));
        int front = 0, rear = 0;
        q[rear++] = st;
        dis[st] = 0;
        inq[st] = true;
        while(front < rear){
            int u = q[front++];
    
    
            inq[u] = false;
            for(int i = head[u]; ~i; i = edge[i].next){
                int v = edge[i].v;
                if(edge[i].cap > 0 && dis[v] > dis[u] + edge[i].cost + eps){
                    dis[v] = dis[u] + edge[i].cost;
                    pre[v] = u;
                    path[v] = i;
                    if(!inq[v]){
                        inq[v] = true;
                        q[rear++] = v;
                    }
                }
            }
        }
        return pre[des] != -1;
        //return dis[des] + eps < INF;
    }
    
    double MCMF(int st, int des){
        double mincost = 0, flow = 0;
        while(SPFA(st, des)){
            int f = INF;
            for(int i = des; i != st; i = pre[i]){
                if(f > edge[path[i]].cap){
                    f = edge[path[i]].cap;
                }
            }
            for(int i = des; i != st; i = pre[i]){
                edge[path[i]].cap -= f;
                edge[path[i]^1].cap += f;
            }
            mincost += f * dis[des];
            flow += f;
        }
        return mincost;
    }
    
    int main(){
        int n,m;
        int _; scanf("%d",&_);
        while(_--) {
            init();
            scanf("%d %d",&n,&m);
            int s = 0; int t = n+1;
            for(int i = 1; i <= n; ++i) {
                int a,b; scanf("%d %d",&a,&b);
                if(a > b) addedge(s,i,a-b,0);
                else if(b > a) addedge(i,t,b-a,0);
            }
            for(int i = 1; i <= m; ++i) {
                int a,b,c; double p; scanf("%d %d %d %lf",&a,&b,&c,&p);
                if(c > 0)addedge(a,b,1,0);
                if(c > 1) addedge(a,b,c-1,-log(1-p) );
            }
            double tt = MCMF(s, t);
            tt = exp(-tt);
            printf("%.2f
    ", 1-tt);
        }
        return 0;
    }
  • 相关阅读:
    ◆◆0[问题解决]REUSE_ALV_FIELDCATALOG_MERGE丢失catalog字段
    不同类型ALV的catalog数据转换[LVC_TRANSFER_TO_SLIS][LVC_TRANSFER_FROM_SLIS]
    ◆◆0ABAP ALV分类以及对应的函数,类小结
    [代码]如何在ALV头中显示Logo图片-[REUSE_ALV_GRID_DISPLAY]
    ◆◆0SALV-如何刷新显示
    ◆◆0[REUSE_ALV_GRID_DISPLAY_LVC]-显示单选按钮(radio button)
    ◆◆0[REUSE_ALV_GRID_DISPLAY_LVC]ALV中字段显示前导零(leading zero)
    ◆◆0[REUSE_ALV_GRID_DISPLAY_LVC]-显示布局按钮(layout button)
    [问题解决]ALV标准过滤功能失效
    ◆◆0SALV-设置SALV选择模式
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8433720.html
Copyright © 2011-2022 走看看