• F


    Almost everyone likes kebabs nowadays (Here a kebab means pieces of meat grilled on a long thin stick). Have you, however, considered about the hardship of a kebab roaster while enjoying the delicious food? Well, here's a chance for you to help the poor roaster make sure whether he can deal with the following orders without dissatisfying the customers. 

    Now N customers is coming. Customer i will arrive at time si (which means the roaster cannot serve customer i until time si). He/She will order ni kebabs, each one of which requires a total amount of ti unit time to get it well-roasted, and want to get them before time ei(Just at exactly time ei is also OK). The roaster has a big grill which can hold an unlimited amount of kebabs (Unbelievable huh? Trust me, it’s real!). But he has so little charcoal that at most M kebabs can be roasted at the same time. He is skillful enough to take no time changing the kebabs being roasted. Can you help him determine if he can meet all the customers’ demand? 

    Oh, I forgot to say that the roaster needs not to roast a single kebab in a successive period of time. That means he can divide the whole ti unit time into k (1<=k<=ti) parts such that any two adjacent parts don’t have to be successive in time. He can also divide a single kebab into k (1<=k<=ti) parts and roast them simultaneously. The time needed to roast one part of the kebab well is linear to the amount of meat it contains. So if a kebab needs 10 unit time to roast well, he can divide it into 10 parts and roast them simultaneously just one unit time. Remember, however, a single unit time is indivisible and the kebab can only be divided into such parts that each needs an integral unit time to roast well. 

    InputThere are multiple test cases. The first line of each case contains two positive integers N and M. N is the number of customers and M is the maximum kebabs the grill can roast at the same time. Then follow N lines each describing one customer, containing four integers: si (arrival time), ni (demand for kebabs), ei (deadline) and ti (time needed for roasting one kebab well). 

    There is a blank line after each input block. 

    Restriction: 
    1 <= N <= 200, 1 <= M <= 1,000 
    1 <= ni, ti <= 50 
    1 <= si < ei <= 1,000,000 
    OutputIf the roaster can satisfy all the customers, output “Yes” (without quotes). Otherwise, output “No”.Sample Input

    2 10
    1 10 6 3
    2 10 4 2
    
    2 10
    1 10 5 3
    2 10 4 2

    Sample Output

    Yes
    No
    题解:建立超级原点start(0),超级汇点endd,超级原点向n个客人连边,权值为总服务时间(n[i]*t[i]),n个客人向离散化后的服务区间(当作点)连边,
    权值为离散后的区间长度乘以m,最后将离散化后的区间向超级汇点连边,权值也为离散化后的区间长度*m,最后Dinic模板判断是否满流即可.


    自己需要注意的一点是:客人离开的那个时间点,是正好离开,所以当前时间点并不能再烤串,因为烤完了后就到下一分钟了,下一分钟客人就不在了,所以不可以.
    #include<iostream>
    #include<string>
    #include<cstring>
    #include<vector>
    #include<queue>
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const int INF=0x3f3f3f3f;
    const int maxn=500010;
    int w[maxn];
    struct edge
    {
        int v,cap,rev;
    };
    int level[maxn],iter[maxn];
    vector<edge>G[maxn];
    void add(int u,int v,int cap)
    {
        G[u].push_back((edge){v,cap,(int)G[v].size()});
        G[v].push_back((edge){u,0,(int)G[u].size()-1});
    }
    void bfs(int s)
    {
        memset(level,-1,sizeof(level));
        queue<int>que;
        level[s]=0;
        que.push(s);
        while(!que.empty()){
            int u=que.front();
            que.pop();
            for(int i=0;i<G[u].size();i++){
               edge &e=G[u][i];
               int v=e.v;
               if(e.cap>0&&level[v]<0){
                level[v]=level[u]+1;
                que.push(v);
               }
            }
        }
    }
    int dfs(int u,int t,int f)
    {
        if(u==t)return f;
        for(int &i=iter[u];i<G[u].size();i++){
            edge &e=G[u][i];
            int v=e.v;
            if(e.cap>0&&level[v]>level[u]){
                int d=dfs(v,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[v][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }
    int Dinic(int s,int t)
    {
        int flow=0;
        for(;;){
            bfs(s);
            if(level[t]<0)return flow;
            memset(iter,0,sizeof(iter));
            int f;
            while((f=dfs(s,t,INF))>0){
                flow+=f;
            }
        }
        return flow;
    }
    int lsh[maxn],cnt;
    int s[maxn],ni[maxn],e[maxn],ti[maxn];
    int n,m;
    int main()
    {
        while(cin>>n>>m){
            for(int i=0;i<=1100;i++)G[i].clear();
            memset(lsh,0,sizeof(lsh));
            int full_flow=0;
            cnt=0;
            for(int i=1;i<=n;i++){
                cin>>s[i]>>ni[i]>>e[i]>>ti[i];
                lsh[++cnt]=s[i];
                lsh[++cnt]=e[i];
                full_flow+=ni[i]*ti[i];
            }
            sort(lsh+1,lsh+1+cnt);
            int len=unique(lsh+1,lsh+1+cnt)-(lsh+1);
            int start=0,endd=1000;
            for(int i=1;i<=n;i++){
                add(start,i,ni[i]*ti[i]);
            }
            for(int i=1;i<=n;i++){
                for(int j=1;j<len;j++){
                    if(lsh[j]>=s[i]&&lsh[j+1]<=e[i]){
                        add(i,n+j,(lsh[j+1]-lsh[j])*m);
                    }
                }
            }
            for(int i=1;i<len;i++){
                add(n+i,endd,(lsh[i+1]-lsh[i])*m);
            }
            int flow=Dinic(start,endd);
            if(flow==full_flow)cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    网络问题排查
    SpringBoot 自定义注解清除缓存
    MYSQL外键的使用以及优缺点
    Java List
    黑客帝国代码雨
    前端接收字节数据流,显示图片
    何为熔断降级
    spring的线程
    window.open 与 iframe
    js 全部替换
  • 原文地址:https://www.cnblogs.com/cherish-lin/p/11392917.html
Copyright © 2020-2023  润新知