zoukankan      html  css  js  c++  java
  • SD第九届省赛B题 Bullet

    Bullet

    Time Limit: 1000 ms Memory Limit: 65536 KiB

    Problem Description

    In GGO, a world dominated by gun and steel, players are fighting for the honor of being the strongest gunmen. Player Shino is a sniper, and her aimed shot kills one monster at a time. Now she is in an n imes nn×n map, and there are monsters in some grids. Each monster has an experience. As a master, however, Shino has a strange self-restrain. She would kill at most one monster in a column, and also at most one in a row. Now she wants to know how to get max experience, under the premise of killing as many monsters as possible.

    Input

    The first line contains an integer nn. (n<=500)
    Then n lines follow. In each line there are n integers, and AijAij represents the experience of the monster at grid (i,j)(i,j). If Aij=0Aij=0, there is no monster at grid (i,j)(i,j).

    The experience is the minimal experience of all the monster which are killed.

    It guaranteed that the maximum of the experience of the monster is not larger than 10^9

    Output

    One integer, the value of max experience.

    Sample Input

    2
    2 0
    1 8

    Sample Output

    2

    Hint

     

    Source

    “浪潮杯”山东省第九届ACM大学生程序设计竞赛(感谢山东财经大学)
     
    求获得最大匹配 用到的经验值的最小值最大化
    就是一个水二分 + 匹配
    记得只对w不为0的i和j建边
    先求出最大匹配max_flow 
    然后二分最小值就好了
    我的最小值最大化板子翻车了。。。。。。
    我用的Dinic写的  匈牙利就好了
     
    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <cctype>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <bitset>
    #define rap(i, a, n) for(int i=a; i<=n; i++)
    #define rep(i, a, n) for(int i=a; i<n; i++)
    #define lap(i, a, n) for(int i=n; i>=a; i--)
    #define lep(i, a, n) for(int i=n; i>a; i--)
    #define rd(a) scanf("%d", &a)
    #define rlld(a) scanf("%lld", &a)
    #define rc(a) scanf("%c", &a)
    #define rs(a) scanf("%s", a)
    #define rb(a) scanf("%lf", &a)
    #define rf(a) scanf("%f", &a)
    #define pd(a) printf("%d
    ", a)
    #define plld(a) printf("%lld
    ", a)
    #define pc(a) printf("%c
    ", a)
    #define ps(a) printf("%s
    ", a)
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 1e6 + 10, INF = 0x7fffffff;
    int n, s, t;
    int head[maxn], cur[maxn], vis[maxn], d[maxn], cnt, nex[maxn << 1];
    
    struct node
    {
        int u, v, c;
    }Node[maxn << 1];
    
    void add_(int u, int v, int c)
    {
        Node[cnt].u = u;
        Node[cnt].v = v;
        Node[cnt].c = c;
        nex[cnt] = head[u];
        head[u] = cnt++;
    }
    
    void add(int u, int v, int c)
    {
        add_(u, v, c);
        add_(v, u, 0);
    }
    
    bool bfs()
    {
        queue<int> Q;
        mem(d, 0);
        Q.push(s);
        d[s] = 1;
        while(!Q.empty())
        {
            int u = Q.front(); Q.pop();
            for(int i = head[u]; i != -1; i = nex[i])
            {
                int v = Node[i].v;
                if(!d[v] && Node[i].c > 0)
                {
                    d[v] = d[u] + 1;
                    Q.push(v);
                    if(v == t) return 1;
                }
            }
        }
        return d[t] != 0;
    }
    
    int dfs(int u, int cap)
    {
        int ret = 0;
        if(u == t || cap == 0)
            return cap;
        for(int &i = cur[u]; i != -1; i = nex[i])
        {
            int v = Node[i].v;
            if(d[v] == d[u] + 1 && Node[i].c > 0)
            {
                int V = dfs(v, min(cap, Node[i].c));
                Node[i].c -= V;
                Node[i ^ 1].c += V;
                ret += V;
                cap -= V;
                if(cap == 0) break;
            }
        }
        if(cap > 0) d[u] = -1;
        return ret;
    }
    
    int Dinic()
    {
        int ans = 0;
        while(bfs())
        {
            memcpy(cur, head, sizeof head);
            ans += dfs(s, INF);
        }
        return ans;
    }
    
    int w[550][550];
    
    void build(int m)
    {
        mem(head, -1);
        cnt = 0;
        for(int i = 1; i <= n; i++)
        {
            add(s, i, 1);
            add(n + i, t, 1);
            for(int j = 1; j <= n; j++)
                if(w[i][j] >= m)
                    add(i, n + j, 1);
        }
    
    
    }
    
    
    int main()
    {
        while(cin >> n)
        {
            int sum = 0;
            mem(head, -1);
            cnt = 0;
            s = 0, t = maxn - 1;
            int l = 1e9, r = 0;
            for(int i = 1; i <= n; i++)
            {
                add(s, i, 1);
                add(n + i, t, 1);
                for(int j = 1; j <= n; j++)
                {
                    rd(w[i][j]);
                    if(w[i][j])
                        add(i, n + j, 1);
                    l = min(l, w[i][j]);
                    r = max(r, w[i][j]);
                }
            }
            int max_flow = Dinic();
    
            while(l < r)
            {
                int m = (l + r + 1) / 2;
                build(m);
                if(Dinic() < max_flow) r = m - 1;
                else l = m;
            }
            cout << r << endl;
        }
    
        return 0;
    }
    View Code
     
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    Spyder 快捷键大全
    上传代码到github,出现 git@github.com: Permission denied (publickey) 错误
    Linux ubuntu 安装 openssh-server 报错
    win10删除「此电脑」中的文档、视频、音乐、下载、图片、桌面等6个文件夹的方法
    IDEA 光标闪烁问题
    委托、Action泛型委托、Func泛型委托、Predicate泛型委托的用法
    C#6.0的新语法特性
    创建多个网站
    发送短信功能(C#)
    VS开发Windows服务
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/10715685.html
Copyright © 2011-2022 走看看