百練/2017大学院生のアップデート試験E:Railway tickets

5098 ワード

タイトルのソース:http://poj.org/problem?id=2355
Railway tickets
------------------------------------------
Time Limit: 1000 MS
メモリLimit: 65536 K
Total Submissions: 3418
Acceepted: 1188
Description
The Lalway line「Ekaterinburg-verdndleofsk」with several statinshas been built.Thisralway line can be represented as a line segment,ralway statis.The RAlway line starts the stastastation「Eververararartititittttttttwos」Eververrererererererererererererereesented asasasasass s s s s s s s s s s s s s s s s s s s s s s s s s s s s s s thethetherererererererererererererererererereprininininininininin」(it has number 1)and「Sverdlast station」。 
Cost of the ticket between any two stations depends only on a distance betwenthem.The prices for the tickets are specifed in the following table. 
distance between stations-X
price for the ticket
0C 1
L 1C 2
L 2C 3
Direct tickets from one station to another can be bookd if and only if thedistance between thers station does not exceed L 3.So sometimes it necessaryto book several tickets to pay for the parts of the whole bertens.the。 For example,on the ralway line shown at the figre abobobobobobook.The diret ticket from the second to the sixth one can.The e e e are e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e e and otherat price C 3 to travel between thethird and the sixth statins.Note、that though the distance between the secondand the sixth statitititititititititititititititititititititititititititititititititititititiaat t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t t 2 2 2 2、the aaaaaaaattttbubububububububububububububububububububulalalalalalalalalalalalalalalatitititititins. Your task is to write a program、that will find the minimal cost of the travel between two given stations.
Input
The first line of the input file contains 6 integers L 1,L 3,C 1,C 2,C 3(1==L 1Output
Program shuld print to the output file theonly number,which is the minimal travel costit between two givent stations.
Sample Input
3 6 8 20 30 40
7
2 6
3
7
8
13
15
23
Sample Output
70
------------------------------------------
問題を解く構想
一次元ダイナミック企画問題(二次元ダイナミック企画解としても考えられますが、時間の複雑さは超えています。)難しい点は3種類あります。3つの双端行列で現在の計算ノードがチケットコースに等しいサイトより小さいという複雑度O(n)です。チケット経路内のノードを前方に検索する過程を回避しました。
------------------------------------------
コード
//   :    

/*       discuss    ,  AC 
*/

#include
#include
#include
#include
#include
using namespace std;

int main()
{
    vector L;
    vector C;
    int i=0, tmp=0, j=0, k=0;
    for (i=0; i<3; i++)
    {
        cin >> tmp;
        L.push_back(tmp);
    }
    for (i=0; i<3; i++)
    {
        cin >> tmp;
        C.push_back(tmp);
    }
    int sN = 0;
    cin >> sN;                          // # of stations
    int src=0, dst=0;
    cin >> src >> dst;
    vector len;
    len.push_back(0);                   //      
    for (i=0; i> tmp;
        len.push_back(tmp);
    }

	if (dst == src)											//     =    
	{
		cout << 0;
		return 0;
	}
	else if(dst < src)										//          
	{
		swap(dst,src);
	}
	int m = dst - src;
    vector dp0;                                        //       0
	deque q[3];			//       :  (j+src-1)<=L[k]   (k=0,1,2)
	// initialization
	for (i=0; i<3; i++)
	{
		q[i].push_back(src-1);
	}
	dp0.push_back(0);
	for (i=1; i=dp0.at(j))
			{
				q[k].pop_back();
			}
			q[k].push_back(j+src-1);
		}
	}
	cout << dp0.at(m);
	
	return 0;
}