Advertisement
Kimossab

Code vs Zombie

Nov 28th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. /**
  9.  * Save humans, destroy zombies!
  10.  **/
  11.  
  12.  typedef struct human
  13.  {
  14.      int id;
  15.      int x;
  16.      int y;
  17.  }HUMAN;
  18.  
  19.  typedef struct zombie
  20.  {
  21.      int id;
  22.      int x;
  23.      int y;
  24.      int nx;
  25.      int ny;
  26.  }ZOMBIE;
  27.  
  28. bool CanReachTime(int x, int y, HUMAN *h, int i, int d)
  29. {
  30.     int moves, moves2;
  31.     moves = (sqrt((h[i].x-x)*(h[i].x-x) + (h[i].y-y)*(h[i].y-y))-2000) / 1000;
  32.     moves2 = d/400;
  33.     cerr << "ASH: " << moves << " ZOMBIE: " << moves2 << " DISTANCE: " << d << endl;
  34.     return moves<=moves2;
  35. }
  36.  
  37. int CheckZombieCloseHuman(HUMAN *h, int hc, ZOMBIE *z, int zc, int x, int y)
  38. {
  39.     int distance = 200000, d, id=0, auxid=-1, d2, moves, mindist=20000000;
  40.     bool human = false;
  41.  
  42.     for(int i=0; i<zc; i++)
  43.     {
  44.         human = false;
  45.         distance = sqrt((x-z[i].x)*(x-z[i].x) + (y-z[i].y)*(y-z[i].y));
  46.         for(int j=0; j<hc; j++)
  47.         {
  48.             d = sqrt((h[j].x-z[i].x)*(h[j].x-z[i].x) + (h[j].y-z[i].y)*(h[j].y-z[i].y));      
  49.             if(d < distance)
  50.             {
  51.                 distance = d;
  52.                 human = true;
  53.                 d2 = j;
  54.             }
  55.         }
  56.         if(human && distance < mindist && CanReachTime(x,y,h,d2,distance))
  57.         {
  58.             mindist = distance;
  59.             auxid=i;
  60.         }
  61.     }
  62.     cerr << "FINAL CHOICE : " << auxid << endl;
  63.     return auxid;
  64. }
  65.  
  66. void ImTarget(HUMAN *h, int hc, ZOMBIE *z, int zc, int x, int y)
  67. {
  68.     if(zc == 1)
  69.         cout << z[0].x << " " << z[0].y << " C'm'ere" << endl;
  70.     else
  71.     {
  72.         int mx=0, my=0;
  73.         for (int i = 0; i < zc; i++)
  74.         {
  75.             mx +=z[i].x;
  76.             my +=z[i].y;
  77.         }
  78.         mx/=zc;
  79.         my/=zc;
  80.         y=my-1000;
  81.         x=mx;
  82.         if(y<0)
  83.             y=0;
  84.         cout << x << " " << y << " Im Taget" <<  endl;
  85.     }
  86. }
  87.  
  88. int main()
  89. {
  90.     int x;
  91.     int y;
  92.     int humanCount;
  93.     int zombieCount;
  94.     int zmx=20000,zmy=20000,zmax=0,zmay=0;
  95.     HUMAN *humans;
  96.     ZOMBIE *zombies;
  97.     while (1)
  98.     {
  99.         cin >> x >> y; cin.ignore();
  100.         cin >> humanCount; cin.ignore();
  101.         humans = new HUMAN[humanCount];
  102.         for (int i = 0; i < humanCount; i++)
  103.         {
  104.             cin >> humans[i].id >> humans[i].x >> humans[i].y; cin.ignore();
  105.         }
  106.         cin >> zombieCount; cin.ignore();
  107.         zombies = new ZOMBIE[zombieCount];
  108.         for (int i = 0; i < zombieCount; i++)
  109.         {
  110.             cin >> zombies[i].id >> zombies[i].x >> zombies[i].y >> zombies[i].nx >> zombies[i].ny; cin.ignore();
  111.         }
  112.         cerr << zmax <<endl;
  113.        
  114.         if(humanCount > 1)
  115.         {
  116.            
  117.             int aux = CheckZombieCloseHuman(humans, humanCount, zombies, zombieCount,x,y);
  118.                
  119.             if(aux == -1)
  120.                 ImTarget(humans, humanCount, zombies, zombieCount,x,y);
  121.             else
  122.                 cout << zombies[aux].x << " " << zombies[aux].y << " HOW TO GET COMBO? FU" << endl;
  123.         }
  124.         else
  125.             cout << humans[0].x << " " << humans[0].y << " PROTECT SCARED HUMAN" << endl;
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement