AlexandruT

Priority queue #2

Jul 6th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. using namespace std;
  5.  
  6. struct Coord
  7. {
  8.     int x, y, cost;
  9.     bool operator < (const Coord &v) const
  10.     {
  11.         return cost > v.cost;
  12.     }
  13. };
  14.  
  15. priority_queue <Coord> q;
  16.  
  17. int main()
  18. {
  19.     int i;
  20.     Coord v;
  21.     for(i = 1; i <= 10; i++)
  22.     {
  23.         v.x = i;
  24.         v.y = 2 * i;
  25.         v.cost = (i * i) % 13;
  26.         q.push(v);
  27.     }
  28.     while(!q.empty())
  29.     {
  30.         v = q.top();
  31.         q.pop();
  32.         cout << v.x << " " << v.y << " " << v.cost << "\n";
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment