<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Hdu Task Schedule

      View Code
        1 #include <iostream>//SAP 最大流應用
        2 #include<cstdio>
        3 #include<cstring>
        4 #include<vector>
        5 #include<queue>
        6 #include<algorithm>
        7 using namespace std;
        8 #define min(a,b) ((a)<(b))?(a):(b)
        9 #define max(a,b) ((a)>(b))?(a):(b)
       10 #define MAXN 1111+10
       11 #define MAXM 505000+10//M取N的平方倍
       12 #define INF 0x3f3f3f3f
       13 
       14 //鏈式前向星
       15 struct enode
       16 {
       17     int t;
       18     int w;                //權值
       19     int c;                //流量
       20 //  int cost;
       21 //    int pre;            //前向指針
       22     int next;
       23 };
       24 
       25 
       26     struct enode e[MAXM];
       27     int box[MAXN],ecnt;
       28     //int etail[MAXN];        //尾部
       29     void init()
       30     {
       31         ecnt=0;
       32         memset(box,-1,sizeof(box));
       33     //    memset(etail,-1,sizeof(etail));        //初始化尾部
       34     }
       35     void addedge(int f,int t,int c)            //流量重載
       36     {
       37         e[ecnt].next=box[f];
       38         e[ecnt].t=t;
       39         e[ecnt].c=c;
       40         box[f]=ecnt++;
       41         e[ecnt].next=box[t];
       42         e[ecnt].t=f;
       43         e[ecnt].c=0;
       44         box[t]=ecnt++;
       45     }
       46 int sap(int s,int t,int N)//最大流問題
       47 {
       48     int gap[MAXN],lvl[MAXN],cur[MAXN],pre[MAXN];
       49     int curflow,ans=0,u,tmp,neck,i;
       50     memset(lvl,0,sizeof(lvl));
       51     memset(gap,0,sizeof(gap));
       52     memset(pre,-1,sizeof(pre));
       53     for(i=0;i<N;i++)
       54         cur[i]=box[i];
       55     gap[0]=N;
       56     u=s;
       57     while(lvl[s]<N)
       58     {
       59         if(u==t)
       60         {
       61             curflow=INF;
       62             for(i=s;i!=t;i=e[cur[i]].t)
       63             {
       64                 if(curflow>e[cur[i]].c)
       65                 {
       66                     neck=i;
       67                     curflow=e[cur[i]].c;
       68                 }
       69             }
       70             for(i=s;i!=t;i=e[cur[i]].t)
       71             {
       72                 tmp=cur[i];
       73                 e[tmp].c-=curflow;
       74                 e[tmp^1].c+=curflow;
       75             }
       76             ans+=curflow;
       77             u=neck;
       78         }
       79         for(i=cur[u];i!=-1;i=e[i].next)
       80             if(e[i].c && lvl[u]==lvl[e[i].t]+1)
       81                 break;
       82         if(i!=-1)
       83         {
       84             cur[u]=i;
       85             pre[e[i].t]=u;
       86             u=e[i].t;
       87         }
       88         else
       89         {
       90             if(--gap[lvl[u]]==0)
       91                 break;
       92              cur[u]=box[u];
       93             for(tmp=N,i=box[u];i!=-1;i=e[i].next)
       94                 if(e[i].c)
       95                     tmp=min(tmp,lvl[e[i].t]);
       96             lvl[u]=tmp+1;
       97             gap[lvl[u]]++;
       98             if(u!=s)
       99                 u=pre[u];
      100         }
      101     }
      102     return ans;
      103 }
      104 int main()
      105 {
      106       int m,n,i,j,t;
      107       scanf("%d",&t);
      108       int ct=1;
      109         while(t--)
      110         {
      111             int pi,si,ei;
      112             int start,end,totals,max,ans;//起點/匯點/總網絡結點/最大ei/總天數
      113             start=max=ans=0;
      114             cin>>n>>m;
      115            // memset(map,0,sizeof(map));
      116             init();
      117             for(i=1;i<=n;i++)
      118             {
      119                 cin>>pi>>si>>ei;
      120                 addedge(start,i,pi);
      121                 max=max>ei?max:ei;
      122                 ans+=pi;
      123                 for(j=si;j<=ei;j++)
      124                 {
      125                     addedge(i,n+j,1);
      126                 }//任務&每天:每天只能處理一個任務
      127             }//參數含義:源點 匯點 網絡結點數量*/
      128             end=1+max+n;
      129             totals=end+1;
      130             for(i=1;i<=max;i++)
      131             {
      132                 addedge(n+i,end,m);
      133             }
      134       /*  for(int i=1;i<=totals;i++)
      135         {
      136             for(int k=box[i];k!=-1;k=e[k].next)
      137                 cout<<i<< " " <<e[k].t<< " " <<e[k].c<<endl;
      138         }*/
      139             if(sap(start,end,totals)==ans)
      140         //    cout<<"Case "<<ct++<<":"<<" Yes\n\n";
      141        //else cout<<"Case "<<ct++<<":"<<" No\n\n";
      142       // cout<<sap(start,end,totals)<<endl;
      143             //cout<<endl;
      144              cout<<"Case "<<ct++<<": Yes\n\n" ;
      145         else cout<<"Case "<<ct++<<": No\n\n" ;
      146         }
      147     return 0;
      148 }
      149 /*
      150 Sample Input
      151 
      152 2
      153 4 3
      154 1 3 5
      155 1 1 4
      156 2 3 7
      157 3 5 9
      158 2 2
      159 2 1 3
      160 1 2 2
      161 
      162 Sample Output
      163 
      164 Case 1: Yes
      165 
      166 Case 2: Yes
      167 
      168 */

      http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1003&ojid=0&cid=4456&hide=0

      /*
      題意:用m個機器,處理n個任務,每個任務必須在[si,ei]時間段完成,需要pi天才能完成。每個機器只能處理一個任務,
      即每天只能處理m個任務。
      題解: 采用最大流,
      建圖:把每個任務和每一天看做一個點,增加源點s和匯點t,在s和每個任務之間連一條邊,容量為持續
      天數;在每一天和t之間連一條邊,容量為m;在每個任務和對應天數之間連一條邊,容量為1。然后最大流量即為所求。
      實現:sap算法
      (網上提到 關于sap詳細介紹參見:http://chuanwang66.iteye.com/blog/1450715
      其中涉及到三種優化,這一部分講的特別好。
      主要思路為:首先建立鄰接表,然后建立層次圖,查找最短最廣路徑。)

      */

      posted on 2013-04-18 23:01  ACM_Someone like you  閱讀(263)  評論(0)    收藏  舉報

      導航

      主站蜘蛛池模板: 依依成人精品视频在线观看| 少妇被粗大的猛烈进出视频 | 国产乱人伦偷精品视频下| 丰满少妇高潮惨叫久久久| 狠狠色噜噜狠狠狠777米奇小说| 国产普通话对白刺激| av无码av无码专区| 影音先锋大黄瓜视频| 国产99视频精品免费视频36| 九九热爱视频精品视频| 99久热在线精品视频| 精品91在线| 日本区二区三区不卡视频| 亚洲成人av在线高清| 国产成人免费午夜在线观看| 国产精品一区二区三区自拍| AV最新高清无码专区| 亚洲天堂一区二区三区三州| 丁香五月激情综合色婷婷| 亚洲国产日韩一区三区| 自拍偷拍一区二区三区四| 亚洲国产精品久久电影欧美 | 一区二区三区四区亚洲自拍| 四虎影院176| 国内精品自在拍精选| 中文字幕日韩欧美就去鲁| 国产精品亚洲中文字幕| 免费视频爱爱太爽了| a级亚洲片精品久久久久久久| 人妻少妇乱子伦精品| 夜色福利站WWW国产在线视频| 最近最好的2019中文| 国产免费网站看v片元遮挡| 日本久久一区二区免高清| 一区一区三区产品乱码| 精品无码国产污污污免费| 激情综合色综合啪啪开心| 亚洲青青草视频在线播放| 亚洲欧美偷国产日韩| 日韩一区二区三区女优丝袜 | 狠狠色狠狠色综合日日不卡|