青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

pku 1203 Timetable 拆點(diǎn)+DP最短路

題意:
Timetable
Time Limit: 3000MS  Memory Limit: 65536K
Total Submissions: 281  Accepted: 86

Description

You are the owner of a railway system between n cities, numbered by integers from 1 to n. Each train travels from the start station to the end station according to a very specific timetable (always on time), not stopping anywhere between. On each station a departure timetable is available. Unfortunately each timetable contains only direct connections. A passenger that wants to travel from city p to city q is not limited to direct connections however -- he or she can change trains. Each change takes zero time, but a passenger cannot change from one train to the other if it departs before the first one arrives. People would like to have a timetable of all optimal connections. A connection departing from city p at A o'clock and arriving in city q at B o'clock is called optimal if there is no connection that begins in p not sooner than at A and ends in q not later than at B. We are only interested in connections that can be completed during same day.
Write a program that:
reads the number n and departure timetable for each of n cities from the standard input,
creates a timetable of optimal connections from city 1 to city n,
writes the answer to the standard output.
Input

The first line of the input contains an integer n (2 <= n <= 100000). The following lines contain n timetables for cities 1, 2, ..., n respectively.

The first line of the timetable description contains only one integer m. Each of the following m lines corresponds to one position in the timetable and contains: departure time A, arrival time B (A < B) and destination city number t (1 <= t <= n) separated by single spaces. Departure time A and arrival time B are written in format hh:mm, where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59). Positions in the timetable are given in non-decreasing order according to the departure times. The number of all positions in all timetables does not exceed 1000000.

Output

The first line of the output contains an integer r -- the number of positions in the timetable being the solution. Each of the following r lines contains a departure time A and an arrival time B separated by single space. The time format should be like in the input and positions in the timetable should be ordered increasingly according to the departure times. If there is more then one optimal connection with the same departure and arrival time, your program should output just one.
Sample Input

3
3
09:00 15:00 3
10:00 12:00 2
11:00 20:00 3
2
11:30 13:00 3
12:30 14:00 3
0
Sample Output

2
10:00 14:00
11:00 20:00
Hint

Huge input data, use scanf instead of cin to avoid time limit exceed.
Source

Southwestern Europe 2002

代碼:

  1Source Code
  2
  3Problem: 1203  User: yzhw 
  4Memory: 36324K  Time: 1485MS 
  5Language: G++  Result: Accepted 
  6
  7Source Code 
  8# include <cstdio>
  9# include <set>
 10# include <vector>
 11# include <cstring>
 12# include <iostream>
 13# include <algorithm>
 14using namespace std;
 15struct node
 16{
 17    char s[10],e[10];
 18    int nxt;
 19}
;
 20int n,m;
 21vector<node> data[100001];
 22vector<int> l[100001];
 23int s[100001];
 24int g[1000005],nxt[2000005],v[2000005],co=0,dp[1000005];
 25int change(char *ori)
 26{
 27    char tmp[10];
 28    strcpy(tmp,ori);
 29    return atoi(strtok(tmp,":"))*60+atoi(strtok(NULL,":"));
 30}

 31void addedge(int s,int e)
 32{
 33    v[co]=e;
 34    nxt[co]=g[s];
 35    g[s]=co++;
 36}

 37int solve(int pos)
 38{
 39    if(dp[pos]!=-1return dp[pos];
 40    else if(g[pos]==-1&&pos>=s[n-1]) return dp[pos]=l[n][pos-s[n-1]];
 41    else
 42    {
 43        dp[pos]=(pos>=s[n-1]?l[n][pos-s[n-1]]:0xfffffff);
 44        for(int p=g[pos];p!=-1;p=nxt[p])
 45            dp[pos]=min(dp[pos],solve(v[p]));
 46        return dp[pos];
 47        
 48    }

 49}

 50void print(int time)
 51{
 52    printf("%s%d:%s%d",time/60<10?"0":"",time/60,time%60<10?"0":"",time%60);
 53}

 54int main()
 55{
 56  //  freopen("in11","r",stdin);
 57  //  freopen("ans.txt","w",stdout);
 58    scanf("%d",&n);
 59    s[0]=0;
 60    for(int i=1;i<=n;i++)
 61    {
 62        scanf("%d",&m);
 63        while(m--)
 64        {
 65            node tmp;
 66            scanf("%s%s%d",tmp.s,tmp.e,&tmp.nxt);
 67            data[i].push_back(tmp);
 68            l[i].push_back(change(tmp.s));
 69            if(tmp.nxt==n) l[n].push_back(change(tmp.e));
 70        }

 71        sort(l[i].begin(),l[i].end());
 72        vector<int>::iterator end=unique(l[i].begin(),l[i].end());
 73        while(l[i].end()!=end) l[i].pop_back();
 74        s[i]=s[i-1]+l[i].size();
 75    }

 76    memset(g,-1,sizeof(g));
 77    memset(dp,-1,sizeof(dp));
 78    co=0;
 79    for(int i=1;i<=n;i++)
 80    {
 81        for(int j=s[i-1];j<s[i]-1;j++)
 82             addedge(j,j+1);
 83        for(int j=0;j<data[i].size();j++)
 84            if(lower_bound(l[data[i][j].nxt].begin(),l[data[i][j].nxt].end(),change(data[i][j].e))!=l[data[i][j].nxt].end())
 85                addedge(s[i-1]+lower_bound(l[i].begin(),l[i].end(),change(data[i][j].s))-l[i].begin(),s[data[i][j].nxt-1]+lower_bound(l[data[i][j].nxt].begin(),l[data[i][j].nxt].end(),change(data[i][j].e))-l[data[i][j].nxt].begin());
 86
 87    }

 88    vector<pair<int,int> >ans;
 89    for(int i=s[1]-1;i>=0;i--)
 90        if(solve(i)!=0xfffffff&&(ans.empty()||solve(i)<ans.back().second))
 91            ans.push_back(make_pair(l[1][i],solve(i)));
 92    printf("%d\n",ans.size());
 93    for(int i=ans.size()-1;i>=0;i--)
 94    {
 95        print(ans[i].first);
 96        printf(" ");
 97        print(ans[i].second);
 98        printf("\n");
 99    }

100//    system("pause");
101    return 0;
102    
103}

104
105

posted on 2010-12-09 21:25 yzhw 閱讀(475) 評(píng)論(0)  編輯 收藏 引用 所屬分類: DPgraph

<2011年2月>
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112

導(dǎo)航

統(tǒng)計(jì)

公告

統(tǒng)計(jì)系統(tǒng)

留言簿(1)

隨筆分類(227)

文章分類(2)

OJ

最新隨筆

搜索

積分與排名

最新評(píng)論

閱讀排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产一区二区三区在线观看精品| 亚洲日本电影在线| 黄色成人在线| 国内一区二区在线视频观看| 国产色婷婷国产综合在线理论片a| 国产精品视频自拍| 黑人一区二区三区四区五区| 亚洲电影免费观看高清完整版在线观看| 激情欧美一区二区| 亚洲人午夜精品免费| 亚洲最新在线| 久久国内精品自在自线400部| 榴莲视频成人在线观看| 亚洲精品在线一区二区| 午夜精品久久久久久久99樱桃| 久久久久久久综合狠狠综合| 欧美成人精品h版在线观看| 欧美三级在线| 在线免费观看一区二区三区| 夜久久久久久| 久久在线视频| 一级成人国产| 免费日本视频一区| 国产欧美日韩伦理| 在线一区二区日韩| 亚洲成色777777女色窝| 亚洲影院色在线观看免费| 男女激情视频一区| 国产一区av在线| 亚洲午夜视频在线| 欧美国产国产综合| 久久国产一区二区| 国产美女精品免费电影| 亚洲人成网站999久久久综合| 欧美一区二区三区四区在线| 最新高清无码专区| 久久精品视频免费| 国产精品婷婷午夜在线观看| 亚洲精品免费在线观看| 久久午夜精品| 欧美一区二区三区四区夜夜大片 | 正在播放欧美一区| 久久综合99re88久久爱| 国产日韩精品在线| 日韩视频在线永久播放| 亚洲欧美激情精品一区二区| 蜜桃av一区二区| 欧美一区二区精美| 国产精品亚洲аv天堂网| 亚洲视频综合| 亚洲美女啪啪| 欧美精品1区2区3区| 在线欧美福利| 老司机精品视频网站| 性欧美暴力猛交69hd| 国产精品欧美一区二区三区奶水| 日韩视频亚洲视频| 亚洲国产综合在线看不卡| 免费短视频成人日韩| 91久久国产精品91久久性色| 欧美在线视频观看| 欧美一区二区免费视频| 国产欧美日韩视频| 欧美在线免费观看视频| 香蕉乱码成人久久天堂爱免费| 国产精品系列在线播放| 欧美在线黄色| 久久久久久有精品国产| 亚洲高清不卡| 亚洲黄色一区| 欧美深夜福利| 久久九九精品99国产精品| 欧美在线一区二区三区| 在线免费观看欧美| 亚洲另类自拍| 国产日韩精品一区二区三区在线| 久久本道综合色狠狠五月| 久久精品成人欧美大片古装| 亚洲成在人线av| 亚洲欧洲在线免费| 国产精品丝袜白浆摸在线| 另类尿喷潮videofree| 欧美久久久久久久| 久久不见久久见免费视频1| 久久一区亚洲| 亚洲影音先锋| 久久综合九色| 亚洲一区二区三区777| 欧美一区二区在线免费观看| 最近看过的日韩成人| 亚洲一区二区三区精品在线观看| 国内精品美女在线观看| 亚洲精品少妇网址| 国产一区自拍视频| 亚洲精品日韩在线观看| 国产曰批免费观看久久久| 最新成人av网站| 黑人一区二区三区四区五区| 99在线精品观看| 伊人久久亚洲影院| 亚洲婷婷免费| 一区二区三区高清不卡| 久久久国产视频91| 亚洲欧美一区二区三区极速播放| 久久人人爽国产| 亚洲综合精品| 欧美久久久久免费| 国产一区二区电影在线观看| 亚洲第一福利视频| 亚洲天堂免费在线观看视频| **欧美日韩vr在线| 亚洲欧美日韩久久精品| 亚洲美女区一区| 久久久精品国产一区二区三区| 一区二区三区四区蜜桃| 另类春色校园亚洲| 久久成人一区二区| 国产精品久久久999| 亚洲国产色一区| 在线电影国产精品| 久久aⅴ乱码一区二区三区| 亚洲欧美在线看| 欧美四级剧情无删版影片| 亚洲国产精品va在线看黑人| 狠狠综合久久| 亚洲欧美激情一区二区| 亚洲神马久久| 欧美日韩亚洲在线| 亚洲精品日韩精品| 一区二区三区国产精华| 欧美日韩aaaaa| 亚洲激情精品| 亚洲精品一级| 欧美国产在线观看| 亚洲第一精品影视| 亚洲国产黄色片| 久久深夜福利免费观看| 久久久亚洲精品一区二区三区| 国产性天天综合网| 欧美中文字幕| 另类专区欧美制服同性| 亚洲国产精品一区制服丝袜| 免费成人性网站| 日韩亚洲欧美一区| 亚洲欧美日本视频在线观看| 国产精品豆花视频| 亚洲欧美激情一区| 看片网站欧美日韩| 亚洲日本理论电影| 欧美日韩免费一区| 亚洲一区二区在线观看视频| 欧美综合77777色婷婷| 激情欧美一区二区三区在线观看| 久久成人资源| 亚洲啪啪91| 亚洲欧美另类在线| 激情亚洲一区二区三区四区| 久久色在线播放| 99精品欧美| 久久先锋影音av| 日韩视频在线观看国产| 国产精品久久久久久久电影| 欧美一区二区三区四区夜夜大片| 免费永久网站黄欧美| 夜夜嗨av色一区二区不卡| 国产美女精品| 欧美精品在线观看| 欧美尤物巨大精品爽| 亚洲激情网址| 久久久国产精品亚洲一区| 日韩视频三区| 狠狠v欧美v日韩v亚洲ⅴ| 欧美α欧美αv大片| 亚洲影视在线播放| 亚洲国产欧美另类丝袜| 欧美一级在线播放| 日韩午夜在线播放| 国产精品麻豆成人av电影艾秋| 久久成人国产| 国产精品亚洲综合| 免费成人av资源网| 西瓜成人精品人成网站| 亚洲夫妻自拍| 久久国产精品久久久| 夜夜爽www精品| 在线观看欧美精品| 国产精品日韩欧美大师| 欧美福利视频网站| 久久亚洲精品伦理| 午夜精品久久久久久久久久久久久 | 免费亚洲网站| 欧美呦呦网站| 亚洲欧美日韩专区| 中文无字幕一区二区三区| 欧美jizz19性欧美| 久久精品人人做人人综合| 亚洲一区二区三区在线观看视频| 亚洲激情视频网| 亚洲国产成人久久| 狠狠综合久久av一区二区老牛|