⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 assemblyline.cpp

📁 implementation of assembly line algorithm given in cormen
💻 CPP
字号:
//******************** Arunanshu Pandey*************************************
//assembly line scheduling mine 

#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int fast[2][n],dist[2][n];
    int s;int f[n];
    for(int i=0;i<n;i++){
               
               cin>>fast[0][i]>>fast[1][i]>>dist[0][i]>>dist[1][i];
               if(i==0){if(fast[0][0]<=fast[1][0])
                        {f[0]=1; 
                          s=fast[0][0];
                          }
                         else{
                              f[0]=2; 
                           s=fast[1][0];
                              } 
                        } 
                  //get the current position      
               else if( f[i-1]==1 ){
                    //1 is the station index
                       if(fast[0][i]<=(fast[1][i]+dist[0][i-1]))
                           {s+=fast[0][i];
                             f[i]=1;
                             
                           // cout<<s<<"++++"<<endl;
                            }
                       else{s+=(fast[1][i]+dist[0][i-1]);
                            f[i]=2;
                             
                            
                           // cout<<s<<"+--+"<<endl;
                            }
                             }     
               else if(f[i-1]==2){
                    //2 is the station index
                       if(fast[1][i]<=(fast[0][i]+dist[1][i-1]))
                           {s+=fast[1][i];
                            f[i]=2;
                              
                            
                            //cout<<s<<"+))+"<<endl;
                            }
                       else{s+=(fast[0][i]+dist[1][i-1]);
                            f[i]=1;
                           
                            
                           // cout<<s<<"+((+"<<endl;
                            }             
                            
                                     } 
               
               
               }
    
    for(int ii=0;ii<n;ii++)cout<<"line  : "<<f[ii]<<" and station : "<< ii+1<<endl;
    cout<<"shortest distance :"<<s<<endl;
    system("pause");
    return 0;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -