Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. // Struktūrų apsirašymas
  10. struct Car
  11. {
  12.     int x, y;
  13.     int vx, vy;
  14. };
  15.  
  16. struct Wreck
  17. {
  18.     int x, y;
  19. };
  20.  
  21. int main()
  22. {
  23.     // game loop
  24.     while (1) {
  25.        
  26.         // Gaunam informaciją iš žaidimo
  27.         int myScore;
  28.         cin >> myScore; cin.ignore();
  29.         int enemyScore1;
  30.         cin >> enemyScore1; cin.ignore();
  31.         int enemyScore2;
  32.         cin >> enemyScore2; cin.ignore();
  33.        
  34.         int myRage;
  35.         cin >> myRage; cin.ignore();
  36.         int enemyRage1;
  37.         cin >> enemyRage1; cin.ignore();
  38.         int enemyRage2;
  39.         cin >> enemyRage2; cin.ignore();
  40.        
  41.         int unitCount;
  42.        
  43.         // Apsirašom mašinėles
  44.         Car reaper;
  45.         Car destro;
  46.         Car doof;
  47.         Car reaper1;
  48.         // Apsirašom balų ir tankerių sarašus
  49.         vector<Wreck> wreck;
  50.         vector<Car> tanker;
  51.        
  52.         cin >> unitCount; cin.ignore();
  53.         // Pereinam per visus unit ir susirenkam informaciją
  54.         for (int i = 0; i < unitCount; i++) {
  55.             int unitId;
  56.             int unitType;
  57.             int player;
  58.             float mass;
  59.             int radius;
  60.             int x;
  61.             int y;
  62.             int vx;
  63.             int vy;
  64.             int extra;
  65.             int extra2;
  66.             cin >> unitId >> unitType >> player >> mass >> radius >> x >> y >> vx >> vy >> extra >> extra2; cin.ignore();
  67.            
  68.             if(unitType == 0 && player == 0) // Susirandam savo reaper ir jo koordinates, pagreitį
  69.             {
  70.                 reaper.x = x;
  71.                 reaper.y = y;
  72.                 reaper.vx = vx;
  73.                 reaper.vy = vy;
  74.             }
  75.            
  76.             if(unitType == 0 && player == 1) // Susirandam priešininko reaper ir jo koordinates, pagreitį
  77.             {
  78.                 reaper1.x = x;
  79.                 reaper1.y = y;
  80.                 reaper1.vx = vx;
  81.                 reaper1.vy = vy;
  82.             }
  83.            
  84.             if(unitType == 1 && player == 0) // Susirandam savo destroyer ir jo koordinates, pagreitį
  85.             {
  86.                 destro.x = x;
  87.                 destro.y = y;
  88.                 destro.vx = vx;
  89.                 destro.vy = vy;
  90.             }
  91.            
  92.             if(unitType == 2 && player == 0) // Susirandam savo doof ir jo koordinates, pagreitį
  93.             {
  94.                 doof.x = x;
  95.                 doof.y = y;
  96.                 doof.vx = vx;
  97.                 doof.vy = vy;
  98.             }
  99.            
  100.             if(unitType == 3) // Sudedam visus tanker bei jų koordinates, pagreitį į balų vector
  101.             {
  102.                 tanker.push_back({x,y,vx,vy});
  103.             }
  104.            
  105.             if(unitType == 4) // Sudedam visas balas bei jų koordinates, pagreitį į balų vector
  106.             {
  107.                 wreck.push_back({x,y});
  108.             }
  109.         }
  110.        
  111.         int distance = 1000000;
  112.         int nr = -1;
  113.         // Susirandam arčiausią balą ir pasižymim jos numerį
  114.         for(int i = 0; i < wreck.size(); i++)
  115.         {
  116.             int ats = sqrt(pow(reaper.x - wreck[i].x, 2)+pow(reaper.y - wreck[i].y, 2));
  117.            
  118.             if(distance  > ats)
  119.             {
  120.                 distance = ats;
  121.                 nr = i;
  122.             }
  123.         }
  124.  
  125.         // Jeigu radom balą važiuojam link jos su reaper, kitu atveju laukiam
  126.         if(nr == -1)
  127.         {
  128.             cout << "WAIT" << endl;
  129.         }
  130.         else
  131.         {
  132.             cout << wreck[nr].x - reaper.vx << " " << wreck[nr].y - reaper.vy << " 300" << endl;
  133.         }
  134.        
  135.         distance = 1000000;
  136.         nr = -1;
  137.         // Susirandam arčiausią tanker ir pasižymim jo numerį
  138.         for(int i = 0; i < tanker.size(); i++)
  139.         {
  140.             int ats = sqrt(pow(destro.x - tanker[i].x, 2)+pow(destro.y - tanker[i].y, 2));
  141.            
  142.             if(distance  > ats)
  143.             {
  144.                 distance = ats;
  145.                 nr = i;
  146.             }
  147.         }
  148.        
  149.         // Jeigu radom tanker važiuojam link jo su destroyer, kitu atveju laukiam
  150.         if(nr == -1)
  151.         {
  152.             cout << "WAIT" << endl;
  153.         }
  154.         else
  155.         {
  156.             cout << tanker[nr].x + tanker[nr].vx - destro.vx << " " << tanker[nr].y + tanker[nr].vy - destro.vy << " 300" << endl;
  157.         }
  158.        
  159.         // Su doof važiuojam link priešininko, kad jam trugdytume
  160.         cout << reaper1.x + reaper1.vx << " " << reaper1.y + reaper1.vy << " 300" << endl;
  161.     }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement