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

//心得
//如何保持路径,递归的实现 #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. centos+apache+mod_ssl

    参考网站:配置Apache建立openssl证书实现SSL访问:http://blog.51yip.com/apachenginx/958.html用ca工具生成证书的方法:http://hi.bai ...

  2. AutoPlay Menu Builder入门教程

    1 拖动窗口可以设置主界面的窗口大小,在下面有版面预览 2 常用东西介绍.右侧的素材库除了按钮还有图像,背景,音乐等.使用按钮的时候选中需要的按钮样式,双击即可上屏.图形按钮即使可以使用图像作为背景的 ...

  3. redis可视化管理工具Redis Desktop Manager

    Redis Desktop Manager 官方下载地址:https://redisdesktop.com/download

  4. Silverlight 之 创建

          Silverlight 项目文件是您可以使用不同工具来创建和编辑的文本文件.例如,可以使用 Visual Studio 2010 以及 Expression Blend 来创建 Silve ...

  5. MVC4.0网站发布

    一.VS2010下MVC4.0项目的发布 首先,生成网站发布文件. 第一步,"右击"要发布的MVC4.0项目,选择"发布(B)..."选项,如图: 第二步,在& ...

  6. Oracle Data Guard 重要配置参数

    Oracle Data Guard主要是通过为生产数据库提供一个或多个备用数据库(是产生数据库的一个副本),以保证在主库不可用或异常时数据不丢失并通过备用数据库继续提供服务.对于Oracle DG的配 ...

  7. 单链表的增、删、改、减(C++)

    首先是是一个简单的例子,单链表的建立和输出. 程序1.1 #include<iostream> #include<string> using namespace std; st ...

  8. python之函数用法all

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #python之函数用法all #all(iterable) #说明:如果iterable的所有元素不为0.' ...

  9. C#:设置焦点在最小的TabIndex控件上

    private void FocusFirstTabIndex(Control container) { // init search result varialble Control searchR ...

  10. 使用SpringMVC搭建第一个项目

    概述 使用SpringMVC搭建第一个项目,入门教程,分享给大家. 详细 代码下载:http://www.demodashi.com/demo/10596.html 一.概述 1.什么是Spring ...