zoukankan      html  css  js  c++  java
  • Alice's Chance POJ

    Alice's Chance
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 7791   Accepted: 3174

    Description

    Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invite her to play the chief role in their new films. Unfortunately, all these companies will start making the films at the same time, and the greedy Alice doesn't want to miss any of them!! You are asked to tell her whether she can act in all the films. 

    As for a film, 
    1. it will be made ONLY on some fixed days in a week, i.e., Alice can only work for the film on these days; 
    2. Alice should work for it at least for specified number of days; 
    3. the film MUST be finished before a prearranged deadline.

    For example, assuming a film can be made only on Monday, Wednesday and Saturday; Alice should work for the film at least for 4 days; and it must be finished within 3 weeks. In this case she can work for the film on Monday of the first week, on Monday and Saturday of the second week, and on Monday of the third week. 

    Notice that on a single day Alice can work on at most ONE film. 

    Input

    The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a single line containing an integer N (1 <= N <= 20), the number of films. Each of the following n lines is in the form of "F1 F2 F3 F4 F5 F6 F7 D W". Fi (1 <= i <= 7) is 1 or 0, representing whether the film can be made on the i-th day in a week (a week starts on Sunday): 1 means that the film can be made on this day, while 0 means the opposite. Both D (1 <= D <= 50) and W (1 <= W <= 50) are integers, and Alice should go to the film for D days and the film must be finished in W weeks.

    Output

    For each test case print a single line, 'Yes' if Alice can attend all the films, otherwise 'No'.

    Sample Input

    2
    2
    0 1 0 1 0 1 0 9 3
    0 1 1 1 0 0 0 6 4
    2
    0 1 0 1 0 1 0 9 4
    0 1 1 1 0 0 0 6 2
    

    Sample Output

    Yes
    No
    

    Hint

    A proper schedule for the first test case:


    按时间点建边就好了
    。。。1 - 7 写成 1 - 9 emm。。。
    #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 = 1e5 + 10, INF = 0x7fffffff;
    int n, m, s, t;
    int day[15];
    int head[maxn], cur[maxn], d[maxn], vis[maxn], nex[maxn << 1], cnt;
    
    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 u)
    {
        int ans = 0;
        while(bfs())
        {
            memcpy(cur, head, sizeof(head));
            ans += dfs(u, INF);
        }
        return ans;
    }
    
    int main()
    {
        int T;
        rd(T);
        while(T--)
        {
            mem(head, -1);
            cnt = 0;
            rd(n);
            s = 0, t = 500;
            int sum = 0;
            int w;
            rap(i, 1, n)
            {
                rap(j, 1, 9)
                {
                    rd(day[j]);
                }
                rap(j, 1, 7)
                    if(day[j] == 1)
                        rep(k, 0, day[9])
                            add(i, n + k * 7 + j, 1);
                add(s, i, day[8]);
               // cout << day[8] << endl;
                sum += day[8];
            }
            rap(i, n + 1, 400)
                add(i, t, 1);
            if(sum == Dinic(s))
                cout << "Yes" << endl;
            else
                cout << "No" << endl;
    
        }
    
    
        return 0;
    }
    Alice's Chance
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 7791   Accepted: 3174

    Description

    Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invite her to play the chief role in their new films. Unfortunately, all these companies will start making the films at the same time, and the greedy Alice doesn't want to miss any of them!! You are asked to tell her whether she can act in all the films. 

    As for a film, 
    1. it will be made ONLY on some fixed days in a week, i.e., Alice can only work for the film on these days; 
    2. Alice should work for it at least for specified number of days; 
    3. the film MUST be finished before a prearranged deadline.

    For example, assuming a film can be made only on Monday, Wednesday and Saturday; Alice should work for the film at least for 4 days; and it must be finished within 3 weeks. In this case she can work for the film on Monday of the first week, on Monday and Saturday of the second week, and on Monday of the third week. 

    Notice that on a single day Alice can work on at most ONE film. 

    Input

    The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow. Each test case begins with a single line containing an integer N (1 <= N <= 20), the number of films. Each of the following n lines is in the form of "F1 F2 F3 F4 F5 F6 F7 D W". Fi (1 <= i <= 7) is 1 or 0, representing whether the film can be made on the i-th day in a week (a week starts on Sunday): 1 means that the film can be made on this day, while 0 means the opposite. Both D (1 <= D <= 50) and W (1 <= W <= 50) are integers, and Alice should go to the film for D days and the film must be finished in W weeks.

    Output

    For each test case print a single line, 'Yes' if Alice can attend all the films, otherwise 'No'.

    Sample Input

    2
    2
    0 1 0 1 0 1 0 9 3
    0 1 1 1 0 0 0 6 4
    2
    0 1 0 1 0 1 0 9 4
    0 1 1 1 0 0 0 6 2
    

    Sample Output

    Yes
    No
    

    Hint

    A proper schedule for the first test case:
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    父母的房产继承买卖赠予以及网络红包代金券优惠券的国家最新税法规定
    家里这7个地方要装柜子,少装一个都是灾难!
    centos里的压缩解压命令tar总结
    2019年9月2日开学!寒假时间也定了……
    理赔时很容易出差错的3个“隐蔽”点
    Linux命令:用“dirs”、“pushd”、“popd”来操作目录栈
    python金融反欺诈-项目实战
    模型分数分布
    PSi-Population Stability Index (PSI)模型分稳定性评估指标
    Kolmogorov–Smirnov test(KS)
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9971146.html
Copyright © 2011-2022 走看看