算法导论--装备线调度(升序&&降序输出)
题意就先不用讲了吧,感觉自己还没有掌握核心的东西。
//心得
//如何保持路径,递归的实现 #include<iostream>
#include<cstdio>
#include<vector>
#include<stack>
#include<cstring>
using namespace std;
int a[100][100];//time for station
int t[100][100];//time for from Li to Lj
int f[100][100];//recorded time
int l[100][100];//keep trace of fastest ways,比方l[1][6]==2,说明l[1][6]是从
//lines 2过来的
int e[2];//into time
int ss[100];
int x[2];//depart time
int last_time; /*******test data*********
1
6
7 9 3 4 8 4
8 5 6 4 5 7
2 3 1 3 4
2 1 2 2 1
2 4
3 2
*************************/
/********core code******/ int assmbly_line(int m)
{
int ff;
f[1][1]=e[1]+a[1][1];
f[2][1]=e[2]+a[2][1];//開始时比較进入哪一条装配线
// printf("\n%d %d",f[1][1],f[2][1]);
for(int j=2;j<=m;j++){//最优化选择
if(f[1][j-1]+a[1][j]<=f[2][j-1]+a[1][j]+t[2][j-1])
{
f[1][j]=f[1][j-1]+a[1][j];
l[1][j]=1;
// printf("j=%d 1\t",l[1][j]);
}
else
{
f[1][j]=f[2][j-1]+a[1][j]+t[2][j-1];
l[1][j]=2;
// printf("j=%d 2\t",l[2][j]);
}
if(f[2][j-1]+a[2][j]<=f[1][j-1]+t[1][j-1]+a[2][j])
{
f[2][j]=f[2][j-1]+a[2][j];
l[2][j]=2;
// printf("j=%d 2\t",l[2][j]);
}
else
{
f[2][j]=f[1][j-1]+t[1][j-1]+a[2][j];
l[2][j]=1;
// printf("j=%d 1\t",l[2][j]);
}
} if(f[1][m]+x[1]<=f[2][m]+x[2])
{
int i=1; ff=f[1][m]+x[1]; last_time=1;
}
else
{ ff=f[2][m]+x[2];
last_time=2; }
return ff; }
//打印路径降序
void print_lines(int s[100],int ll,int m)
{
int i=ll;
ss[m]=i;//为了后面的升序使用
printf("lines: %d,stations: %d\n",i,m);
for(int j=m;j>=2;j--)
{
i=l[i][j];
printf("lines: %d,stations: %d\n",i,j-1);
ss[j-1]=i;
}
}
//打印路径升序递归
void print_cursion_line( int l[][100],int last_l,int n)
{
int i=last_l;
if(n==1)
printf("Lines %d,stations %d\n",i,n);
else
{
print_cursion_line(l,l[i][n],n-1);
printf("Lines %d,stations %d\n",i,n);
} }
//打印路径非递归
void nocursion_increasing(int ss[100],int m)
{
for(int i=1;i<=m;i++)
printf("lines %d,stations %d\n",ss[i],i);
} //*******core code******//
int main()
{
int m;
freopen("in.txt","r",stdin);
int k;
scanf("%d",&k);//測试的数据块数
while(k--){
memset(a,0,sizeof(a));
memset(t,0,sizeof(t));
memset(f,0,sizeof(f));
memset(l,0,sizeof(l));
memset(e,0,sizeof(e));
memset(x,0,sizeof(x));
scanf("%d",&m);//装配站的数目
for(int i=1;i<=m;i++)
scanf("%d",&a[1][i]);
for(int i=1;i<=m;i++)
scanf("%d",&a[2][i]);
for(int i=1;i<m;i++)
scanf("%d",&t[1][i]);
for(int i=1;i<m;i++)
scanf("%d",&t[2][i]);
for(int i=1;i<=2;i++)
scanf("%d",&e[i]);
for(int i=1;i<=2;i++)
scanf("%d",&x[i]); } printf("\n");
int cai=assmbly_line(m);
printf("The total cast time is %d\n",cai); int ll=last_time;
//下面是打印的路径
printf("decreaing output is \n");
print_lines(l[m],ll,m);
printf("Increaing and oncursion output is \n");
nocursion_increasing(ss,m);
printf("increaing cursion is \n");
print_cursion_line(l,ll,m);
// printf("last_time=%d\n",last_time);
}
算法导论--装备线调度(升序&&降序输出)的更多相关文章
- 奇数结点升序偶数结点降序的单链表排序(Python实现)
题目 一个链表,奇数结点升序,偶数结点降序,要求变成一个全升序的链表. 例如:1->8->2->7->3->6->4->5,变为1->2->3-& ...
- DataTable进行排序Asc升序,Desc降序
DataTable dt = new DataTable(); DataView dv = dt.DefaultView; dv.Sort = "XXX Asc"; dt=dv.T ...
- mysql中的升序和降序以及一个字段升序和一个字段降序
mySql中,升序为asc,降序为desc.例如: 升序:select * from 表名 order by 表中的字段 asc(mysql中默认是升序排列,可不写) 降序:select ...
- SQL-ORDER BY 多字段排序(升序、降序)
ORDER BY _column1, _column2; /* _column1升序,_column2升序 */ ORDER BY _column1, _column2 DESC; /* _col ...
- 升序 Collections.sort(list) 降序 Collections.reserve(list) 随机 Collections.shuffle(list)
package Day28ketangzuoye; import java.util.ArrayList; import java.util.Collections; import java.util ...
- mysql 升序降序
默认不指定,order by 按照升序排列. asc:升序 desc:降序
- mysql中一个字段升序,另一个字段降序
mySql中,升序为asc,降序为desc.例如: 升序:select * from 表名 order by 表中的字段 asc(mysql中默认是升序排列,可不写) 降序:select ...
- sql中使一个字段升序,一个字段降序
ORDER BY _column1, _column2; /* _column1升序,_column2升序 */ ORDER BY _column1, _column2 DESC; /* _colum ...
- LINQ中的OrderBy实现按照两个字段升序、降序排序操作
在公司或许有这种需求,先根据第一个某个字段按照升序排序,然后如果相同,在按照第二个某个字降序排序,我们该怎么去实现呢? 现在来教教大家分别使用Labmda和LINQ进行这种操作. 1.先按照第一个字段 ...
随机推荐
- 30款免费的手机UI设计资源
在 原型设计阶段,我们会尽量寻找一些灵感刺激大脑,从而让我们的想象力飞-灵感给了我们很好的开始,但是当我们把灵感化为现实的时候,又需要一些实用而又高 效的组件来完成.即使你有非常善于把灵感实例化在草稿 ...
- 小米电视支付SDK接入air坑爹之路
1. air的包名在生成android后会加入一个air的前缀变为air.***.***.mibox.包名与appid和appkey必须相相应才行,不然会一直返回40000错误 2. 加入了Nativ ...
- MVC应用积累
1.Controller中的跳转 (1)直接Redirect后加(Controller/Action):Response.Redirect("/Home/Index"); (2)直 ...
- remote: ERROR: missing Change-Id in commit message footer
remote: ERROR: missing Change-Id in commit message footer [摘要:git 提交到近程版本库失足:remote: ERROR: missing ...
- leetcode Wildcard Matching greedy algrithm
The recursive program will result in TLE like this: class Solution { public: bool isMatch(const char ...
- PHP高级教程-文件
PHP 文件处理 fopen() 函数用于在 PHP 中打开文件. 打开文件 fopen() 函数用于在 PHP 中打开文件. 此函数的第一个参数含有要打开的文件的名称,第二个参数规定了使用哪种模式来 ...
- [Oracle] decode 函数及其用法
http://blog.csdn.net/oscar999/article/details/18399177 前言 DECODE()函数,它将输入数值与函数中的参数列表相比较,根据输入值返回一个对应值 ...
- ONVIFclient搜索设备获取rtsp地址开发笔记(精华篇)
概要: 眼下ONVIF协议家族设备已占领数字监控行业半壁江山以上.亲,作为开发人员的你还在犹豫是否了解下吗?本文介绍了ONVIFclient从设备搜索,鉴权,能力获取,媒体信息获取 ...
- 寻找SQL注入点
如果要对一个网站进行SQL注入攻击,首先就需要找到存在SQL注入漏洞的地方,也就是寻找所谓的注入点.可能的SQL注入点一般存在于登录页面.查找页面或添加页面等用户可以查找或修改数据的地方. 最常用的寻 ...
- MySQL查看表结构三种方法
1:desc T1 2:EXPLAIN T1 3:SHOW COLUMNS FROM T1