UVA 10187 From Dusk Till Dawn /PC 110907

不吐槽。。

  1 #include <iostream>
  2 #include <map>
  3 #include <queue>
  4 
  5 //无语的水题。节哀吧。且这道题不严谨,因为没说是无环。算了,不吐槽了。优先队列+BFS 
  6 
  7 using namespace std;
  8 const int inf=10000000;
  9 const int MAxN=105;
 10 const int MAXM=2000;
 11 typedef struct ei{
 12     int v;
 13     int begin;
 14     int ends;
 15 }edge;
 16 vector<edge>Edge[MAxN];
 17 typedef struct ci{
 18     int city;
 19     int litre;
 20     int artime;
 21     bool operator<(const ci &A)const {
 22         return (litre>A.litre) ;
 23     }
 24 }City;
 25 City tmp,pushed;
 26 int m,tot;
 27 int start_city,end_city;
 28 int LITRES;
 29 
 30 void init(){
 31     for(int i=0;i<MAxN;i++)
 32     Edge[i].clear();
 33 }
 34 
 35 void addedge(int u,int v,int be,int en){
 36     Edge[u].push_back((edge){v,be,en});
 37 }
 38 
 39 bool slove(){
 40     int now; int tmptime,pushtime;
 41     priority_queue<City>que;
 42     tmp.city=start_city; tmp.artime=18; tmp.litre=0;
 43     que.push(tmp);
 44     while(!que.empty()){
 45         tmp=que.top();
 46         que.pop();
 47         now=tmp.city;
 48         if(now==end_city){
 49             LITRES=tmp.litre;
 50             return true;
 51         }
 52         for(int e=0;e<Edge[now].size();e++){
 53              tmptime=tmp.artime; pushtime=Edge[now][e].begin;
 54              int used=tmp.litre;
 55             if(pushtime<tmptime){
 56                 used++;
 57             }
 58             que.push((City){Edge[now][e].v,used,Edge[now][e].ends});
 59         }
 60     }
 61     return false;
 62 }
 63 
 64 
 65 int main(){
 66     int T; int from,to; int Cas=0;
 67     string start,ends; int stt,edt,waste;
 68     cin>>T;
 69     while(T--){
 70         Cas++;
 71         init();
 72         map<string,int>citys;
 73         cin>>m;
 74         for (int i = 1; i <= m; i++)
 75         {
 76             cin >> start >> ends >> stt >> waste;
 77             if (citys.find(start) == citys.end())
 78             {
 79                 from = citys.size();
 80                 citys[start] = from;
 81             }
 82             else
 83                 from = citys[start];
 84 
 85             if (citys.find(ends) == citys.end())
 86             {
 87                 to = citys.size();
 88                 citys[ends] = to;
 89             }
 90             else
 91                 to = citys[ends];
 92             if(((stt>=18)||(stt<=6&&stt>=0))){   //我调了一天,把自己原来写的改得面目全非,对着别人的改啊改
 93             //都几乎改成别人的了,终于,一道水题,让我过了。当我把(stt>=18&&stt<=24)改成(stt>=18)之后,过了。哈哈哈
 94             //坑爹的测试数据啊。肯定是有测试数据超过了24。尼玛,还我一早上的时间,kao,一万个操。。 还以为是我的算法错了呢
 95             //原来是测试数据坑.. 
 96                 if(stt<=6)
 97                 stt+=24;
 98                 edt=stt+waste;
 99                 if(edt<=30){
100                 Edge[from].push_back((edge){to,stt,edt});
101                 }
102             }
103 
104         }
105         cin>>start>>ends;
106         if(start==ends){
107             cout << "Test Case " << Cas << "." << endl;
108             cout << "Vladimir needs 0 litre(s) of blood." << endl;
109             continue;
110         }
111             if(citys.find(start)==citys.end()
112                 ||citys.find(ends)==citys.end()){
113             cout << "Test Case " << Cas << "." << endl;
114             cout << "There is no route Vladimir can take." << endl;
115             continue;
116             }
117         start_city=citys[start]; end_city=citys[ends];
118         if(slove()){
119             cout << "Test Case " << Cas << "." << endl;
120             cout << "Vladimir needs " << LITRES << " litre(s) of blood." << endl;
121         }
122         else {
123             cout << "Test Case " << Cas << "." << endl;
124             cout << "There is no route Vladimir can take." << endl;
125         }
126     }
127     return 0;
128 }
View Code

 

posted @ 2014-07-21 21:48  chenjunjie1994  阅读(482)  评论(0编辑  收藏  举报