设为首页 收藏本站
查看: 890|回复: 0

[经验分享] HLG 1061 Boss Xnby’s Scheduling Problem【SAP】

[复制链接]

尚未签到

发表于 2015-9-18 11:57:32 | 显示全部楼层 |阅读模式
Description
  Boss xnby owns a company, as you know, in the company there are lots of jobs to do.Each job J has a processing requirement pj (denoting the number of machine days required to complete the job), a release date rj (representing the beginning of the day when job j becomes avalible for processing), and a due date dj ≥ rj  + pj (representing the beginning of the day by which the job must be completed). What could we do when facing so many jobs? Thank goodness, in xnby’s company, there are some parallel machines can do these jobs.Since a machine can work on only one job at a time and each job can be processed by at most one machine at a time.And preemptions(i.e., we can interrupt a job and process it on different machines on different days) is allowed.Now xnby can use these parallel machines to process these boring jobs,but he also need to determine a feasible schedule that completes all jobs before their due dates or show no such schedule existd.Xnby is a boss, he is a big shot, he had no time to do with these trivial things, so he arranged for you to do this task.

Input
  An integer T (T ≤ 100) indicated the number of test cases.
  For each test cases:
  Two integers J and M (J ≤ 100, M ≤ 100) denote jobs and machines respectively.
  In the following J lines(each job one line, in ascending order), each line contains three integers p, r, d (p ≤ 100,r ≤ 100 and d ≤ 200) denote processing requirement, release date and due date respectively.

Output

For each test case, output “Boss xnby is angry!” if no such schedule exists.Otherwise output “Boss xnby is happy!”.


Sample Input


1

4 3

2 3 5

1 1 4

2 3 7

4 5 9
Sample Output
  Boss xnby is happy!

  
分析:




我们 可以构建一个二部图,每个任务一个节点,每天一个节点,任务和天数满足上述条件就连一条边,容量为  1。再引入一个源点和汇点,从源点向每个任务节点连一条边,容量为该任务的处理时间p,再引入一个汇点,从每个天数节点连一条边至汇点,容量为M,表示从当天的可以使用的机器数。



DSC0000.gif DSC0001.gif View Code


#include<stdio.h>
#include<string.h>
#define INF 0x1f1f1f
int n,m,s,u,e;
int c[300][300],r[300][300];
int gap[300];
int dis[300];
void init()
{
int v,x,q[300],front=0,rear=0;
memset(gap,0,sizeof(gap));
memset(dis,0xff,sizeof(dis));
q[rear++]=u;
dis=0;
while(front<rear)
{
x=q[front++];
gap[dis[x]]++;
for(v=0;v<=e;v++)
if(dis[v]==-1&&c[v][x]>0)
{
dis[v]=dis[x]+1;
q[rear++]=v;
}
}
}
int max_flow()
{
init();
int flow=0,top=s,i,j,k,pre[300],low[300];
memset(low,0,sizeof(low));
while(dis<=e)
{
int flag=0;
low=INF;
for(i=0;i<=e;i++)
{
if(c[top]>0&&dis[top]==dis+1&&dis>=0)
{
flag=1;
break;
}
}
if(flag)
{
low=c[top];
if(low>low[top])
low=low[top];
pre=top;
top=i;
if(top==u)
{
flow+=low;
j=top;
while(j!=s)
{
k=pre[j];
c[k][j]-=low;
c[j][k]+=low;
j=k;
}
top=s;
memset(low,0,sizeof(low));
}
}
else
{
int min=e;
for(j=0;j<=e;j++)
{
if(c[top][j]>0&&dis[j]+1<min&&dis[j]>=0)
min=dis[j]+1;
}
gap[dis[top]]--;
if(gap[dis[top]]==0)
break;
gap[min]++;
dis[top]=min;
if(top!=s)
top=pre[top];
}
}
return flow;
}
int main()
{
//freopen("D:ce.txt","r",stdin);
int st,en,la,tot,i,j,ca;
scanf("%d",&ca);
while(ca--)
{
scanf("%d%d",&n,&m);
tot=0;
memset(c,0,sizeof(c));
s=0;e=0; u=n+1;
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&la,&st,&en);
c=la;
tot+=la;
if(la<=en-st)
for(j=st;j<en;j++)
{
c[n+j+1]=1;
c[n+j+1][n+1]=m;
}
if(n+en>e)
e=en+n;
}
if(max_flow()==tot)
printf("Boss xnby is happy!\n");
else printf("Boss xnby is angry!\n");
}
return 0;
}
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-115355-1-1.html 上篇帖子: SAP凭证冲销(转) 下篇帖子: SAP XI/PI UDF Global Container and Trace
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表