题意就先不用讲了吧,感觉自己还没有掌握核心的东西。

//心得
//如何保持路径,递归的实现 #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);
}

算法导论--装备线调度(升序&amp;&amp;降序输出)的更多相关文章

  1. 奇数结点升序偶数结点降序的单链表排序(Python实现)

    题目 一个链表,奇数结点升序,偶数结点降序,要求变成一个全升序的链表. 例如:1->8->2->7->3->6->4->5,变为1->2->3-& ...

  2. DataTable进行排序Asc升序,Desc降序

    DataTable dt = new DataTable(); DataView dv = dt.DefaultView; dv.Sort = "XXX Asc"; dt=dv.T ...

  3. mysql中的升序和降序以及一个字段升序和一个字段降序

    mySql中,升序为asc,降序为desc.例如: 升序:select   *  from  表名 order by  表中的字段 asc(mysql中默认是升序排列,可不写) 降序:select   ...

  4. SQL-ORDER BY 多字段排序(升序、降序)

    ORDER BY _column1, _column2; /* _column1升序,_column2升序 */   ORDER BY _column1, _column2 DESC; /* _col ...

  5. 升序 Collections.sort(list) 降序 Collections.reserve(list) 随机 Collections.shuffle(list)

    package Day28ketangzuoye; import java.util.ArrayList; import java.util.Collections; import java.util ...

  6. mysql 升序降序

    默认不指定,order by 按照升序排列. asc:升序 desc:降序

  7. mysql中一个字段升序,另一个字段降序

    mySql中,升序为asc,降序为desc.例如: 升序:select   *  from  表名 order by  表中的字段 asc(mysql中默认是升序排列,可不写) 降序:select   ...

  8. sql中使一个字段升序,一个字段降序

    ORDER BY _column1, _column2; /* _column1升序,_column2升序 */ ORDER BY _column1, _column2 DESC; /* _colum ...

  9. LINQ中的OrderBy实现按照两个字段升序、降序排序操作

    在公司或许有这种需求,先根据第一个某个字段按照升序排序,然后如果相同,在按照第二个某个字降序排序,我们该怎么去实现呢? 现在来教教大家分别使用Labmda和LINQ进行这种操作. 1.先按照第一个字段 ...

随机推荐

  1. POJ 1436 Horizontally Visible Segments (线段树&#183;区间染色)

    题意   在坐标系中有n条平行于y轴的线段  当一条线段与还有一条线段之间能够连一条平行与x轴的线不与其他线段相交  就视为它们是可见的  问有多少组三条线段两两相互可见 先把全部线段存下来  并按x ...

  2. LightOj 1123-Trail Maintenance(最小生成树:神级删边)

    1123 - Trail Maintenance PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...

  3. JAR,WAR,EAR区别

    JAR WAR EAR 英文 Java Archive file Web Archive file Enterprise Archive file 包含内容 class.properties文件,是文 ...

  4. 使用Nginx Upstream 部署 OpenERP

    Openerp 6.1 使用werkzeug 作为web服务的框架,性能比之前的cherrypy 有了很大的改善.但无论是 werkzeug 还是cherrypy ,都不是专门的web服务器.通常的做 ...

  5. Flash actionscript3.0 多个setTimeout之间会顺序执行 单线程执行 无法中止

    做了一个试验,测试能否在另外的setTimeout中中断其他代码的执行.结果表明,是不可能的,Actionscript会按顺序,逐个逐个的执行. private var index:int; priv ...

  6. python之函数用法bin()

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法bin() #bin() #说明:一个整数转换为一个二进制字符串 ''' bin(.. ...

  7. 26、线性表(List)

    1.List List接口是Collection的子接口,List是一个可重复集合 2.ArrayList和LinkedList ArrayList和LinkedList是List接口最常见的两个实现 ...

  8. Loadrunner脚本编程(4)-数据类型操作和字符串操作

    http://www.360doc.com/content/10/0806/13/1698198_44078277.shtml 一,数据类型转换 没有使用过C编程的LoadRunner脚本编写者会发现 ...

  9. Chrome实用调试技巧

    如今Chrome浏览器无疑是最受前端青睐的工具,原因除了界面简洁.大量的应用插件,良好的代码规范支持.强大的V8解释器之外,还因为Chrome开发者工具提供了大量的便捷功能,方便我们前端调试代码,我们 ...

  10. 利用ASP.NET一般处理程序动态生成Web图像(转)

    摘自:http://www.cnblogs.com/zhouhb/archive/2011/02/15/1955262.html 一般处理程序的扩展名为ashx,它实现了IHttpHandler接口, ...