zoukankan      html  css  js  c++  java
  • Escape HDU

    Escape

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 13028    Accepted Submission(s): 3264


    Problem Description
    2012 If this is the end of the world how to do? I do not know how. But now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. Now scientists want your help, is to determine what all of people can live in these planets.
     
    Input
    More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet.
    The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
    0 <= ai <= 100000
     
    Output
    Determine whether all people can live up to these stars
    If you can output YES, otherwise output NO.
     
    Sample Input
    1 1 1 1 2 2 1 0 1 0 1 1
     
    Sample Output
    YES NO
     
    Source
     

      裸?毕竟是多校的题,能裸吗。。。有点bishu。。

      看到n和m的范围相差这么大,没点想法吗

      把选择相同的人缩为一个点,顺便统计个数,就是裸了,

      注意用c++交。。。。

      

    #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 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, LL_INF = 0x7fffffffffffffff;
    int n, m, s, t, cnt;
    int head[maxn], d[maxn], cur[maxn];
    map<string, int> se;
    vector<string> g;
    string str;
    struct node
    {
        int u, v, c, next;
    }Node[maxn];
    
    void add_(int u, int v, int c)
    {
        Node[cnt].u = u;
        Node[cnt].v = v;
        Node[cnt].c = c;
        Node[cnt].next = 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 = Node[i].next)
            {
                node e = Node[i];
                if(!d[e.v] && e.c > 0)
                {
                    d[e.v] = d[u] + 1;
                    Q.push(e.v);
                    if(e.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 = Node[i].next)
        {
            node e = Node[i];
            if(d[e.v] == d[u] + 1 && e.c > 0)
            {
                int V = dfs(e.v, min(e.c, cap));
                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 ret = 0;
        while(bfs())
        {
            memcpy(cur, head, sizeof(head));
            ret += dfs(s, INF);
        }
        return ret;
    }
    
    void init()
    {
        mem(head, -1);
        se.clear();
        g.clear();
        cnt = 0;
    }
    
    int main()
    {
        while(~scanf("%d%d", &n, &m))
        {
            getchar();
            init();
            int ans = 0;
            rap(i, 1, n)
            {
                getline(cin, str);
                if(!se[str])
                {
                    ++ans;
                    g.push_back(str);
                    int len = str.size();
                    for(int j = 0; j < len; j++)
                    {
                        if(str[j] == '1')
                            add(10 + ans, (j + 2) / 2, INF);
                    }
                }
                se[str]++;
            }
            s = 0, t = 10 + ans + 1;
            int max_flow = 0;
            for(int i = 0; i < g.size(); i++)
            {
                add(s, 10 + i + 1, se[g[i]]);
                max_flow += se[g[i]];
            }
            int tmp;
            for(int i = 1; i <= m; i++)
            {
                rd(tmp);
                add(i, t, tmp);
            }
            if(max_flow == Dinic())
            {
                printf("YES
    ");
            }
            else
                printf("NO
    ");
    
        }
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    Entity Framework Code First属性映射约定 转载https://www.cnblogs.com/libingql/p/3352058.html
    EntityFrame Work 6 Code First 配置字段为varchar 类型
    【配置属性】—Entity Framework实例详解
    Repository模式--采用EF Fluent API使用EntityTypeConfiguration分文件配置Model映射关系
    JS中$含义及用法
    mvc中@RenderSection()研究 转载https://www.cnblogs.com/rrxc/p/4062827.html
    ASP.Net MVC开发基础学习笔记:三、Razor视图引擎、控制器与路由机制学习
    Windows API中的坑
    Machine Learning—The k-means clustering algorithm
    android BaseAdapter getView 理解
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9830792.html
Copyright © 2011-2022 走看看