博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1776 Task Sequences
阅读量:7030 次
发布时间:2019-06-28

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

 

题意:

有一个机器要完成N个作业,

给你一个N*N的矩阵,

M[i][j]=1,表示完成第i个作业后不用重启机器,继续去完成第j个作业

M[i][j]=0,表示如果做完第i个作业,想要继续去做第j个作业,那么必须重启机器

对于任意两个作业都有M[i][j] = 1或者M[j][i] = 1.

求出完成这N个作业启动机器的最少次数,以及每次启动完成作业的数量和这些作业的顺序

初始时机器处于关闭状态.

 

将M当做图,就是找最少的路径条数覆盖所有的点

最小路径覆盖?

但不能保证图是二分图,所以不能用匈牙利算法

题目中说对于任意两个作业都有M[i][j] = 1或者M[j][i] = 1

所以这张图是在竞赛图的基础上加了几条边

而竞赛图一定存在一条哈密顿通路

所以一定只需要一次开机完成所有作业

然后就是输出竞赛图上的一条哈密顿通路

详请参见文章

 

#include
#include
#include
using namespace std;#define N 1001int n;char s[N<<1];int e[N][N];int front,nxt[N];int st[N];void Hamilton(){ front=1; memset(nxt,0,sizeof(nxt)); for(int i=2;i<=n;++i) { if(e[front][i]) { nxt[i]=front; front=i; continue; } int j,k; for(j=front;j;k=j,j=nxt[j]) if(e[j][i]) { nxt[i]=j; nxt[k]=i; break; } if(!j) nxt[k]=i; }}void print(){ printf("1\n%d\n",n); int now=front; int top=0; while(now) { st[++top]=now; now=nxt[now]; } for(int i=top;i>1;--i) printf("%d ",st[i]); printf("%d\n",st[1]);}int main(){ while(scanf("%d",&n)!=EOF) { memset(e,false,sizeof(e)); for(int i=1;i<=n;++i) { getchar(); scanf("%[^\n]",s); int t=0; for(int j=0;t

 

Task Sequences
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2637   Accepted: 763   Special Judge

Description

Tom has received a lot of tasks from his boss, which are boring to deal with by hand. Fortunately,Tom got a special machine - Advanced Computing Machine (ACM) to help him. 
ACM works in a really special way. The machine can finish one task in a short time, after it's finishing one task, it should smoothly move to the next one, otherwise the machine will stop automatically. You must start it up again to make it continue working. Of course, the machine cannot move arbitrarily from one task to another. So each time before it starts up, one task sequence should be well scheduled. Specially, a single task also can be regarded as a sequence. In the sequence, the machine should be able to smoothly move from one task to its successor (if exists). After started up, the machine always works according to the task sequence, and stops automatically when it finishes the last one. If not all the tasks have been finished, the machine has to start up again and works according to a new sequence. Of course, the finished tasks can't be scheduled again. 
For some unknown reasons, it was guaranteed that for any two tasks i and j, the machine can smoothly move from i to j or from j to i or both. Because the startup process is quite slow, Tom would like to schedule the task sequences properly, so that all the tasks can be completed with minimal number of startup times. It is your task to help him achieve this goal.

Input

Input contains several testcases. For each testcase, the first line contains only one integer n, (0 < n <= 1,000), representing the number of tasks Tom has received. Then n lines follow. Each line contains n integers, 0 or 1, separated by white spaces. If the j
th integer in the i
th line is 1, then the machine can smoothly move from task i to task j, otherwise the machine can not smoothly move from task i to task j. The tasks are numbered from 1 to n. 
Input is terminated by end of file.

Output

For each testcase, the first line of output is only one integer k, the minimal number of startup times needed. And 2k lines follow, to describe the k task sequences. For each task sequence, the first line should contain one integer m, representing the number of tasks in the sequence. And the second line should contain m integers, representing the order of the m tasks in the sequence. Two consecutive integers in the same line should be separated by just one white space. Extra spaces are not allowed. There may be several solutions, any appropriate one is accepted.

Sample Input

30 1 11 0 10 0 0

Sample Output

132 1 3

Source

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8439853.html

你可能感兴趣的文章
我的友情链接
查看>>
Linux命令行快捷键
查看>>
python 的实用技巧
查看>>
创建RHCS集群环境
查看>>
电子商务未来的趋势,难道我真的错了?
查看>>
工厂方法模式
查看>>
360安全卫士怎么登录问题
查看>>
linux下的DNS缓存服务
查看>>
实现一键分享的代码
查看>>
详解Linux运维工程师必备技能
查看>>
[20181109]12c sqlplus rowprefetch参数5
查看>>
bupt summer training for 16 #1 ——简单题目
查看>>
【Udacity】朴素贝叶斯
查看>>
shader 讲解的第二天 把兰伯特模型改成半兰泊特模型 函数图形绘制工具
查看>>
python3.5安装Numpy、mayploylib、opencv等额外库
查看>>
优雅绝妙的Javascript跨域问题解决方案
查看>>
Java 接口技术 Interface
查看>>
函数草稿
查看>>
织梦系统学习:文章页当前位置的写法(自认对SEO有用)
查看>>
PHP经验——PHPDoc PHP注释的标准文档(翻译自Wiki)
查看>>