]> ruin.nu Git - icfp05.git/commitdiff
priority queue instead of a vector which is later sorted
authorMichael Andreen <harv@ruin.nu>
Sun, 26 Jun 2005 22:50:50 +0000 (22:50 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 26 Jun 2005 22:50:50 +0000 (22:50 +0000)
robber/robber.cpp

index 4bc04000f79ff21efba4c7ba2d6e62eb1818fad1..f586f6ae3267a4e95664d54c4c8ec2e9c36d8d38 100644 (file)
@@ -1,6 +1,7 @@
 #include "robber.h"
 #include <iostream>
 #include <iterator>
+#include <queue>
 #include <cmath>
 
 using namespace std;
@@ -53,7 +54,7 @@ string Robber::turn(){
                        continue;
                }
 
-               vector<double> banks;
+               priority_queue<double> banks;
                for(hash_map<string,int>::const_iterator bank = _banks.begin();
                                bank != _banks.end(); ++bank){
                        //cerr << "Handling bank at: " << bank->first << endl;
@@ -63,13 +64,15 @@ string Robber::turn(){
                                        continue;
                                //list<string>::iterator i = l.begin();
                                //++i;
-                               banks.push_back(bank->second/(pow(l.size(),4.0)));
+                               banks.push(bank->second/(pow(l.size(),4.0)));
                        }
                }
-               sort(banks.begin(),banks.end(),greater<double>());
+               //sort(banks.begin(),banks.end(),greater<double>());
 
-               for (unsigned int i = 0; i < 2 && i < banks.size();++i)
-                       goodness += banks[i];
+               for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){
+                       goodness += banks.top();
+                       banks.pop();
+               }
 
                cerr << "Goodness before cop: " << goodness << endl;
                if (closestCop > 2){