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

oyjpArt ACM/ICPC算法程序設(shè)計(jì)空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6

PKU1511 Invitation Cards

Posted on 2007-01-02 16:10 oyjpart 閱讀(1619) 評(píng)論(2)  編輯 收藏 引用 所屬分類: ACM/ICPC或其他比賽

Invitation Cards
Time Limit:3000MS? Memory Limit:65536K
Total Submit:241 Accepted:93

Description
In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessary information and with the programme. A lot of students were hired to distribute these invitations among the people. Each student volunteer has assigned exactly one bus stop and he or she stays there the whole day and gives invitation to people travelling by bus. A special course was taken where students learned how to influence people and what is the difference between influencing and robbery.

The transport system is very special: all lines are unidirectional and connect exactly two stops. Buses leave the originating stop with passangers each half an hour. After reaching the destination stop they return empty to the originating stop, where they wait until the next full half an hour, e.g. X:00 or X:30, where 'X' denotes the hour. The fee for transport between two stops is given by special tables and is payable on the spot. The lines are planned in such a way, that each round trip (i.e. a journey starting and finishing at the same stop) passes through a Central Checkpoint Stop (CCS) where each passenger has to pass a thorough check including body scan.

All the ACM student members leave the CCS each morning. Each volunteer is to move to one predetermined stop to invite passengers. There are as many volunteers as stops. At the end of the day, all students travel back to CCS. You are to write a computer program that helps ACM to minimize the amount of money to pay every day for the transport of their employees.

Input
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case begins with a line containing exactly two integers P and Q, 1 <= P,Q <= 1000000. P is the number of stops including CCS and Q the number of bus lines. Then there are Q lines, each describing one bus line. Each of the lines contains exactly three numbers - the originating stop, the destination stop and the price. The CCS is designated by number 1. Prices are positive integers the sum of which is smaller than 1000000000. You can also assume it is always possible to get from any stop to any other stop.

Output
For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of its volunteers.

Sample Input

2
2 2
1 2 13
2 1 33
4 6
1 2 10
2 1 60
1 3 20
3 4 10
2 4 5
4 1 50

Sample Output

46
210

Source
Central Europe 1998

這個(gè)題目我想就是??糄ijkstra()的堆寫(xiě)法吧 中間我采用的逆轉(zhuǎn)有向邊的寫(xiě)法 可以把從多點(diǎn)到單源的最短路徑用單源到多點(diǎn)的最短路徑的方法求出。
中間出了一個(gè)很隱蔽的錯(cuò)誤 在一個(gè)i, j的雙層循環(huán)中 內(nèi)層循環(huán)寫(xiě)成了i++...結(jié)果調(diào)了很久。。。
總算過(guò)了 發(fā)現(xiàn)STL占內(nèi)存是直接寫(xiě)鄰接表的2倍左右,這也印證了vector的擴(kuò)張方式。

??1 Solution:
??2 // by?Optimistic
??3 #include? < stdio.h >
??4 #include? < string .h >
??5 #include? < vector >
??6 using ? namespace ?std;?
??7
??8 const ? int ?MAXINT? = ? 200000000 ;
??9 // const?double?INF?=?10e100;
?10 // const?double?EPS?=?10e-6;?
?11
?12 const ? int ?N? = ? 1000010 ;
?13 int ?nv,?ne;
?14 typedef? struct { int ?jj,?w;} Vtx;
?15 vector < Vtx > ?adj[N];
?16 vector < Vtx > ?adj2[N];
?17 typedef? struct { int ?k,?no;} hNode;
?18 int ?ntc,?hs;
?19 hNode?h[N];?
?20
?21 bool ? operator ? < ?( const ?hNode & ?a,? const ?hNode & ?b)?
?22 {
?23 ? return ?a.k? < ?b.k;
?24 }
?
?25
?26 void ?push(hNode?t)
?27 {
?28 ? int ?i? = ? ++ hs;
?29 ? while (i? > ? 1 ? && ?t? < ?h[i >> 1 ])? {
?30 ??h[i]? = ?h[i >> 1 ];
?31 ??i? >>= ? 1 ;
?32 ?}

?33 ?h[i]? = ?t;
?34 }
?
?35
?36 void ?pop()
?37 {
?38 ?hs -- ;
?39 ? int ?i? = ? 1 ,?ic? = ? 2 ;
?40 ? while (ic? <= ?hs)? {
?41 ?? if (ic + 1 ? <= ?hs? && ?h[ic + 1 ]? < ?h[ic])?ic ++ ;
?42 ?? if (h[hs + 1 ]? < ?h[ic])? break ;
?43 ??h[i]? = ?h[ic];
?44 ??i? = ?ic;
?45 ??ic? <<= ? 1 ;
?46 ?}

?47 ?h[i]? = ?h[hs + 1 ];
?48 }
?
?49
?50 int ?Dijkstra()
?51 {
?52 ?hs? = ? 0 ;
?53 ? int ?i;
?54 ? int ? * ?dist? = ? new ? int [nv];
?55 ? for (i? = ? 0 ;?i? < ?nv;?i ++ )?dist[i]? = ?MAXINT;
?56 ?hNode?now;
?57 ?now.k? = ? 0 ;?now.no? = ? 0 ;
?58 ?push(now);
?59 ? while ( 1 )
?60 ? {
?61 ?? while (hs? > ? 0 ? && ?h[ 1 ].k? > ?dist[h[ 1 ].no])?
?62 ???pop();
?63 ?? if (hs? == ? 0 )? break ;
?64 ??now? = ?h[ 1 ];
?65 ??pop();
?66 ?? int ?u? = ?now.no;
?67 ??dist[u]? = ?now.k;
?68 ?? for (i? = ? 0 ;?i? < ?adj[u].size();?i ++ )
?69 ?? {
?70 ??? int ?v? = ?adj[u][i].jj;
?71 ??? int ?w? = ?adj[u][i].w;
?72 ??? if (dist[v]? > ?dist[u]? + ?w)
?73 ??? {
?74 ????now.k? = ?dist[u]? + ?w;
?75 ????now.no? = ?v;
?76 ????push(now);
?77 ????dist[v]? = ?dist[u]? + ?w;
?78 ???}

?79 ??}

?80 ?}

?81 ? int ?ans? = ? 0 ;
?82 ? for (i? = ? 0 ;?i? < ?nv;?i ++ )
?83 ??ans? += ?dist[i];
?84 ? return ?ans;
?85 }
?
?86
?87 void ?init()
?88 {
?89 ? int ?i,?u,?v,?w;
?90 ?Vtx?x;
?91 ? // initiation
?92 ? for (i? = ? 0 ;?i? < ?nv;?i ++ )? {
?93 ??adj2[i].clear();
?94 ??adj[i].clear();
?95 ?}

?96 ? // input
?97 ?scanf( " %d?%d " ,? & nv,? & ne);
?98 ? for (i? = ? 0 ;?i? < ?ne;?i ++ )? {
?99 ??scanf( " %d?%d?%d " ,? & u,? & v,? & w);
100 ??u -- ;?v -- ;?
101 ??x.jj? = ?v;?x.w? = ?w;
102 ??adj[u].push_back(x);
103 ?}

104 ? // pretreatment
105 }
?
106
107 void ?Reverse()
108 {
109 ? int ?i,?j;
110 ?Vtx?x;
111 ? for (i? = ? 0 ;?i? < ?nv;?i ++ )
112 ??adj2[i].clear();
113 ? for (i? = ? 0 ;?i? < ?nv;?i ++ )
114 ? {
115 ?? for (j? = ? 0 ;?j? < ?adj[i].size();?j ++ )
116 ?? {
117 ???x.jj? = ?i;
118 ???x.w? = ?adj[i][j].w;
119 ???adj2[adj[i][j].jj].push_back(x);
120 ??}

121 ?}

122 ? for (i? = ? 0 ;?i? < ?nv;?i ++ )
123 ? {
124 ??adj[i].clear();
125 ?? for (j? = ? 0 ;?j < adj2[i].size();?j ++ )
126 ???adj[i].push_back(adj2[i][j]);
127 ?}

128 }
?
129
130 void ?work()
131 {
132 ? int ?x? = ?Dijkstra();
133 ?Reverse();
134 ?x? += ?Dijkstra();
135 ?printf( " %d\n " ,?x);
136 }
?
137
138 int ?main()
139 {
140 // ?freopen("t.in",?"r",?stdin);
141 ?scanf( " %d " ,? & ntc);
142 ? while (ntc -- )
143 ? {
144 ??init();
145 ??work();
146 ?}

147 ? return ? 0 ;
148 }
?
149

Feedback

# re: PKU1511 Invitation Cards   回復(fù)  更多評(píng)論   

2007-04-16 22:38 by bon
while (hs > 0 && h[ 1 ].k > dist[h[ 1 ].no]) pop();
請(qǐng)問(wèn)這一句是什么意思?多謝!

# re: PKU1511 Invitation Cards   回復(fù)  更多評(píng)論   

2007-04-17 13:02 by oyjpart
72 if (dist[v] > dist[u] + w)
73 {
74 now.k = dist[u] + w;
75 now.no = v;
76 push(now);
77 dist[v] = dist[u] + w;
78 }
從這段代碼中可以看到 在一次添加節(jié)點(diǎn)后 并沒(méi)有按照常理對(duì)其他連接的可改進(jìn)節(jié)點(diǎn)做修正(實(shí)際上是模版沒(méi)有擴(kuò)充修改一個(gè)節(jié)點(diǎn)的值然后維護(hù)堆性質(zhì)的功能) 我們把那些舊的節(jié)點(diǎn)稱為廢節(jié)點(diǎn)的話 所以在選出dist最小的節(jié)點(diǎn)的時(shí)候要看看是不是廢節(jié)點(diǎn) 如果是的就要不斷POP出來(lái)
while (hs > 0 && h[ 1 ].k > dist[h[ 1 ].no]) pop();
應(yī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>
            国产欧美精品| 亚洲无毛电影| 亚洲一区二区三区在线观看视频| 亚洲免费视频网站| 久久久久综合一区二区三区| 亚洲成色www8888| 正在播放亚洲一区| 久久综合九色综合欧美狠狠| 欧美日韩一区二区三区在线看 | 亚洲免费电影在线观看| 亚洲欧美区自拍先锋| 欧美xx视频| 亚洲一区二区精品| 欧美高清不卡| 国产专区精品视频| 亚洲影院一区| 亚洲高清不卡一区| 久久精品二区亚洲w码| 欧美日韩免费观看中文| 极品尤物一区二区三区| 亚洲自拍电影| 亚洲国产99精品国自产| 性做久久久久久久免费看| 欧美久久在线| 在线精品亚洲| 久久成人av少妇免费| 亚洲九九九在线观看| 久久免费国产精品1| 国产精品日韩欧美综合| 亚洲美女性视频| 免费欧美在线视频| 欧美一区二区视频在线观看2020| 欧美日韩影院| 亚洲看片免费| 你懂的视频一区二区| 午夜精品影院| 国产精品草草| 一个色综合导航| 欧美国产日韩一区二区在线观看| 欧美专区在线播放| 国产精品午夜视频| 亚洲视频网在线直播| 最新国产精品拍自在线播放| 久久最新视频| 国产一区二区精品久久99| 亚洲欧美国产va在线影院| 91久久精品国产91久久| 欧美a级片网站| 亚洲成人在线网站| 久久夜色精品国产欧美乱| 性欧美大战久久久久久久免费观看 | 欧美伊人久久久久久久久影院| 国产精品国内视频| 在线综合亚洲| 亚洲免费av观看| 欧美日韩美女一区二区| 日韩午夜激情| 亚洲精品护士| 欧美日韩国产成人| 一本色道久久综合| 9久re热视频在线精品| 欧美日韩一区二区在线视频| 一区二区三区日韩欧美精品| 亚洲激情成人网| 欧美日韩国语| 亚洲免费影视| 亚洲欧美另类在线观看| 国产美女精品视频免费观看| 欧美专区18| 欧美一区二区视频97| 国产综合精品| 久久综合一区二区| 久久一区视频| 日韩午夜剧场| 夜夜嗨一区二区| 国产精品一卡二卡| 久久精品一区蜜桃臀影院| 欧美一区视频| 亚洲国产日韩一区二区| 亚洲福利一区| 欧美三级小说| 欧美一级久久久| 欧美在线视频一区二区三区| 伊人久久成人| 亚洲国产另类久久精品| 欧美日韩精品欧美日韩精品一| 亚洲一区二区三区精品在线观看 | 久久久最新网址| 久久久久女教师免费一区| 亚洲日本国产| 一区二区不卡在线视频 午夜欧美不卡在 | 在线中文字幕一区| 亚洲欧美日韩一区二区| 国语自产精品视频在线看8查询8| 久久综合狠狠综合久久激情| 欧美成人精品在线观看| 亚洲欧美成人一区二区三区| 久久爱www.| 亚洲激情在线激情| 9i看片成人免费高清| 国产日韩欧美一区二区| 欧美高清视频一区| 欧美视频专区一二在线观看| 久久久久久久综合| 欧美国产激情二区三区| 午夜欧美不卡精品aaaaa| 久久久国产精品一区二区中文| 亚洲欧洲一区| 午夜精品视频| 亚洲人成网站在线播| 在线亚洲免费视频| 在线观看成人av电影| 99精品99久久久久久宅男| 国产亚洲欧美一区二区| 91久久久久久久久| 国产一区91| 亚洲精品综合精品自拍| 狠狠色综合网站久久久久久久| 日韩视频在线永久播放| 黄色成人av网站| 一区二区国产日产| 在线观看精品一区| 亚洲天堂网在线观看| 亚洲国产精品成人| 亚洲欧美日韩另类| av成人毛片| 久久久午夜精品| 欧美亚洲一级| 欧美乱人伦中文字幕在线| 久久久亚洲成人| 国产精品黄视频| 亚洲韩国日本中文字幕| 激情亚洲一区二区三区四区| 亚洲一区二区不卡免费| 亚洲美洲欧洲综合国产一区| 久久精品人人做人人爽电影蜜月| 亚洲一区免费| 欧美另类69精品久久久久9999| 久久久亚洲精品一区二区三区 | 国产在线观看91精品一区| 日韩视频不卡中文| 最新亚洲激情| 久久九九久精品国产免费直播| 亚洲一区二区三区免费观看 | 亚洲小说春色综合另类电影| 久久精品人人做人人爽| 欧美一区二区精品| 欧美亚洲成人精品| 91久久国产综合久久91精品网站| 永久域名在线精品| 亚久久调教视频| 午夜日韩激情| 国产精品久久久久久久久果冻传媒| 亚洲成色999久久网站| 一区在线视频| 欧美一区二区三区视频在线观看| 亚洲一区二区三区国产| 欧美人妖另类| 亚洲国产日韩一级| 亚洲人成毛片在线播放女女| 久久网站免费| 久久夜色撩人精品| 韩国视频理论视频久久| 欧美亚洲三区| 久久九九有精品国产23| 国产一二精品视频| 欧美一级二区| 久久―日本道色综合久久| 国产综合网站| 久久蜜桃精品| 亚洲大胆视频| 亚洲精品黄色| 欧美精品在线极品| 91久久精品国产91性色| 日韩视频国产视频| 欧美伦理一区二区| 亚洲经典在线| 亚洲视频精品| 国产精品久久久久久av下载红粉 | 激情丁香综合| 久久夜精品va视频免费观看| 美女视频一区免费观看| 亚洲黄色在线看| 欧美日本国产一区| 日韩视频一区二区三区| 亚洲一区二区在线免费观看视频 | 久久精品2019中文字幕| 国产一区二区中文| 久久久午夜电影| 亚洲高清视频在线| 在线一区亚洲| 国产精品亚洲综合一区在线观看 | 亚洲国产欧美在线| 欧美成人中文| 一区二区久久| 久久国产精品99国产精| 亚洲第一毛片| 欧美日本不卡视频| 亚洲一区二区三区在线看| 久久―日本道色综合久久|