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

oyjpArt ACM/ICPC算法程序設計空間

// 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) 評論(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

這個題目我想就是專考Dijkstra()的堆寫法吧 中間我采用的逆轉有向邊的寫法 可以把從多點到單源的最短路徑用單源到多點的最短路徑的方法求出。
中間出了一個很隱蔽的錯誤 在一個i, j的雙層循環中 內層循環寫成了i++...結果調了很久。。。
總算過了 發現STL占內存是直接寫鄰接表的2倍左右,這也印證了vector的擴張方式。

??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   回復  更多評論   

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

# re: PKU1511 Invitation Cards   回復  更多評論   

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 }
從這段代碼中可以看到 在一次添加節點后 并沒有按照常理對其他連接的可改進節點做修正(實際上是模版沒有擴充修改一個節點的值然后維護堆性質的功能) 我們把那些舊的節點稱為廢節點的話 所以在選出dist最小的節點的時候要看看是不是廢節點 如果是的就要不斷POP出來
while (hs > 0 && h[ 1 ].k > dist[h[ 1 ].no]) pop();
應該很好理解了
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            毛片av中文字幕一区二区| 香蕉av777xxx色综合一区| 欧美国产视频一区二区| 亚洲欧美电影在线观看| 久久久91精品国产| 99re66热这里只有精品4| 亚洲一区二区伦理| 亚洲人体偷拍| 性欧美18~19sex高清播放| 亚洲激情在线观看视频免费| 亚洲亚洲精品在线观看| 国产精品久久久久高潮| 亚洲激情视频网站| 激情久久中文字幕| 日韩亚洲国产欧美| 亚洲高清一区二| 性欧美xxxx大乳国产app| 亚洲视频1区| 欧美aⅴ一区二区三区视频| 久久久国产午夜精品| 欧美香蕉视频| 日韩视频在线一区二区三区| 在线成人激情| 久久精品国产在热久久| 性色av一区二区三区红粉影视| 欧美精品日韩| 亚洲国产精品一区二区www在线 | 亚洲伊人伊色伊影伊综合网| 亚洲国产精品一区| 欧美中文字幕在线观看| 午夜视频一区在线观看| 欧美亚男人的天堂| 日韩一级二级三级| 99精品热6080yy久久| 猫咪成人在线观看| 免费久久久一本精品久久区| 狠狠做深爱婷婷久久综合一区| 一区二区免费在线观看| 在线视频欧美日韩精品| 国产精品一二一区| 久久国产加勒比精品无码| 卡通动漫国产精品| 日韩视频在线一区| 欧美午夜宅男影院| 欧美在线影院| 亚洲韩国精品一区| 亚洲一区网站| 激情国产一区| 欧美日韩黄视频| 亚洲欧美国产高清| 欧美激情视频在线播放| 亚洲图色在线| 一区三区视频| 欧美日韩国产bt| 午夜国产不卡在线观看视频| 欧美电影免费观看高清| 亚洲欧美日韩国产| 亚洲国产婷婷香蕉久久久久久99| 欧美日韩国产免费| 久久精品欧美日韩| 99精品国产高清一区二区 | 欧美aa国产视频| 亚洲午夜免费视频| 亚洲第一精品福利| 国产精品高潮粉嫩av| 久久天堂成人| 日韩午夜剧场| 欧美成人激情在线| 欧美亚洲在线| 一本久道综合久久精品| 一区在线视频观看| 国产精品美女久久福利网站| 免费中文字幕日韩欧美| 午夜电影亚洲| 国产精品99久久久久久宅男| 免费久久99精品国产自在现线| 午夜精品福利一区二区三区av| 亚洲激情成人在线| 韩日精品视频一区| 国产精品一区二区久激情瑜伽| 欧美国产精品专区| 久久青青草原一区二区| 午夜欧美理论片| 一区二区三区欧美| 亚洲精品国产精品国自产观看浪潮| 久久欧美肥婆一二区| 亚洲女同性videos| 亚洲视频在线免费观看| 亚洲精品资源美女情侣酒店| 国产专区一区| 国产一区二区三区四区老人| 国产精品v欧美精品∨日韩| 欧美区一区二区三区| 免费试看一区| 两个人的视频www国产精品| 久久精选视频| 欧美一区二区三区在线观看| 亚洲一区在线播放| 亚洲免费视频成人| 亚洲女性喷水在线观看一区| 一区二区三区精品久久久| 亚洲精品一品区二品区三品区| 欧美激情女人20p| 欧美激情a∨在线视频播放| 欧美成人高清视频| 欧美激情久久久久| 91久久久久| 亚洲精品在线看| 日韩网站在线观看| 99www免费人成精品| 洋洋av久久久久久久一区| 亚洲乱码精品一二三四区日韩在线| 亚洲破处大片| 亚洲精品综合精品自拍| 亚洲精品一区二区网址| 99精品视频免费观看视频| 一区二区久久久久| 亚久久调教视频| 久久久精品国产免大香伊| 亚洲男人的天堂在线| 亚洲欧美精品在线| 欧美专区在线播放| 久久久久国产成人精品亚洲午夜| 久久伊人精品天天| 亚洲黄色av一区| 一区电影在线观看| 欧美一乱一性一交一视频| 久久久久国色av免费观看性色| 久久只有精品| 欧美日韩在线观看一区二区| 国产精品久久一级| 国产一区二区久久久| 亚洲国产精品嫩草影院| 99国产精品一区| 午夜精品国产| 欧美成在线观看| 亚洲激情一区二区| 亚洲综合久久久久| 美女久久一区| 国产精品毛片a∨一区二区三区| 国产亚洲成精品久久| 亚洲国产精品成人va在线观看| 一本不卡影院| 久久免费黄色| 夜久久久久久| 另类综合日韩欧美亚洲| 国产精品无人区| 亚洲精品乱码久久久久久蜜桃麻豆| 夜夜嗨av一区二区三区四季av| 久久www成人_看片免费不卡| 欧美黄色影院| 午夜精品福利电影| 欧美日韩另类在线| 在线看一区二区| 欧美一区二区三区久久精品| 亚洲高清一区二| 欧美在线综合视频| 国产精品免费看| 日韩亚洲不卡在线| 巨乳诱惑日韩免费av| 夜夜嗨av一区二区三区网站四季av | 亚洲小说欧美另类社区| 免费观看国产成人| 午夜精品亚洲一区二区三区嫩草| 欧美大片第1页| 一区视频在线看| 欧美在线综合| 亚洲一区二区不卡免费| 欧美人成在线| 亚洲精品一区二区在线| 久久在线视频| 欧美一区二区在线看| 国产精品白丝av嫩草影院| 日韩视频中午一区| 欧美激情精品久久久久久久变态 | 亚洲国产视频一区| 久久免费精品日本久久中文字幕| 亚洲少妇自拍| 欧美午夜不卡视频| 日韩一区二区精品视频| 亚洲第一区中文99精品| 久久精品女人的天堂av| 国内精品久久久久久久影视麻豆| 午夜免费电影一区在线观看| 夜夜夜久久久| 国产精品久久久久久久久借妻| aⅴ色国产欧美| 亚洲精品影视| 欧美另类高清视频在线| 夜夜精品视频| 日韩一级不卡| 国产精品乱人伦一区二区| 亚洲一区久久| 亚洲一区二区在线播放| 国产精品羞羞答答| 久久免费高清| 免费观看亚洲视频大全| 亚洲免费av观看| 中文国产成人精品| 国产片一区二区|