博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1534 Schedule Problem (差分约束)
阅读量:6991 次
发布时间:2019-06-27

本文共 3897 字,大约阅读时间需要 12 分钟。

Schedule Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1085    Accepted Submission(s): 448
Special Judge


Problem Description
A project can be divided into several parts. Each part should be completed continuously. This means if a part should take 3 days, we should use a continuous 3 days do complete it. There are four types of constrains among these parts which are FAS, FAF, SAF and SAS. A constrain between parts is FAS if the first one should finish after the second one started. FAF is finish after finish. SAF is start after finish, and SAS is start after start. Assume there are enough people involved in the projects, which means we can do any number of parts concurrently. You are to write a program to give a schedule of a given project, which has the shortest time.
 

 

Input
The input file consists a sequences of projects.
Each project consists the following lines:
the count number of parts (one line) (0 for end of input)
times should be taken to complete these parts, each time occupies one line
a list of FAS, FAF, SAF or SAS and two part number indicates a constrain of the two parts
a line only contains a '#' indicates the end of a project
 
 

 

Output
Output should be a list of lines, each line includes a part number and the time it should start. Time should be a non-negative integer, and the start time of first part should be 0. If there is no answer for the problem, you should give a non-line output containing "impossible".
A blank line should appear following the output for each project.
 

 

Sample Input
3 2 3 4 SAF 2 1 FAF 3 2 # 3 1 1 1 SAF 2 1 SAF 3 2 SAF 1 3 # 0
 

 

Sample Output
Case 1: 1 0 2 2 3 1 Case 2: impossible
 

 

Source
 

 

Recommend
LL   |   We have carefully selected several similar problems for you:            
 
1 //0MS    248K    1537 B    G++ 2 /* 3  4     题意: 5         给出完成作业需要的时间,以及它们间完成的先后关系,问是否可行,可行输出每个作业的开始时间 6          7     差分约束: 8      9         有n个作业,第 i 个作业所需的时间是 a[i];10 11         SAS u v 表示 v开始后 u 才能开始;f(u)>=f(v);12 13         SAF u v 表示 v结束后 u 才能开始;f(u)+a[u]>=f(v);14 15         FAF u v 表示 v结束后 u 才能结束;f(u)+a[u]>=f(v)+a[v];16 17         FAS u v 表示 v开始后 u 才能结束;f(u)>=f(v)+a[v] 18  19     这里使用bellman_ford算法,建立反向边,求最长路径 20     21 */22 #include
23 #include
24 #define N 100525 #define inf 0x7ffffff26 struct node{27 int u,v,w;28 }edge[4*N];29 int d[N];30 int a[N];31 int n,edgenum;32 bool bellman_ford()33 {34 memset(d,0,sizeof(d));35 bool flag=true;36 for(int i=0;i<=n;i++){37 if(!flag) break;38 flag=false;39 for(int j=0;j

 

 再贴一个SPFA的:

1 //218MS    456K    1791 B    G++ 2 #include
3 #include
4 #include
5 #define N 1005 6 #define inf 0x7ffffff 7 using namespace std; 8 struct node{ 9 int v,w;10 node(int a,int b){11 v=a;w=b;12 }13 };14 vector
V[N];15 int a[N];16 int d[N],in[N],vis[N];17 int n;18 bool spfa()19 {20 memset(in,0,sizeof(in));21 memset(vis,0,sizeof(vis));22 for(int i=0;i<=n;i++) d[i]=-inf;23 queue
Q;24 Q.push(0);25 vis[0]=1;26 in[0]=1;27 d[0]=0;28 while(!Q.empty()){29 int u=Q.front();30 Q.pop();31 if(in[u]>n) return false;32 vis[u]=0;33 int n0=V[u].size();34 for(int i=0;i
>n)55 {56 if(!n) break;57 for(int i=0;i<=n;i++) V[i].clear();58 for(int i=1;i<=n;i++){59 cin>>a[i];60 V[0].push_back(node(i,0));61 }62 while(cin>>opr){63 if(opr=="#") break;64 cin>>x>>y;65 if(opr=="SAS") V[y].push_back(node(x,0));66 if(opr=="SAF") V[y].push_back(node(x,a[y]));67 if(opr=="FAS") V[y].push_back(node(x,-a[x]));68 if(opr=="FAF") V[y].push_back(node(x,a[y]-a[x]));69 }70 cout<<"Case "<
<<":"<
View Code

 

转载于:https://www.cnblogs.com/GO-NO-1/p/3442204.html

你可能感兴趣的文章
Missing key(s) in state_dict: Unexpected key(s) in state_dict
查看>>
sqlconnection,sqlcommand,sqldataadapter,sqldatareader,dataset都是做什么用的?
查看>>
mysql字符集说明
查看>>
linux 动态库 静态库 函数覆盖
查看>>
nginx代理天地图做缓存解决跨域问题
查看>>
SQL MAP 注入测试
查看>>
Android开机自启动程序
查看>>
php弱类型
查看>>
vim
查看>>
【转载】MapReduce编程 Intellij Idea配置MapReduce编程环境
查看>>
安装配置管理 之 Fedora 6.0 蓝牙bluebooth传送文件的问题解决方法
查看>>
C 结构
查看>>
spring 加载不了jdbc.properties文件的数据问题
查看>>
JQuery Plugin 2 - Passing Options into Your Plugin
查看>>
长尾分布(幂律分布)
查看>>
Android提高--索引
查看>>
队列(Queue)-c实现
查看>>
DevExpress控件使用系列--ASPxGridView+Popup+Tab
查看>>
MySql5.7配置文件my.cnf设置
查看>>
set names utf8;
查看>>