Advertisement
Guest User

04_Task4_Antimatter

a guest
Jul 15th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. // 01_04_Task4_Antimatter.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream> //for std::cout
  6. #include <string>
  7. #include <sstream>
  8. #include <iomanip>
  9. #include <vector>  
  10. #include <utility>  //pair<vey, value>
  11. #include<list>
  12.  
  13. using namespace std;
  14.  
  15. class Point
  16. {
  17. private:
  18.     char type;
  19.     int x;
  20.     int y;
  21.     int speedX;
  22.     int speedY;
  23.     int lifetime;
  24. public:
  25.     Point()
  26.     {}
  27.     Point(char type, int posX, int posY, int speedX, int speedY, int lifetime) :
  28.         type(type), x(posX), y(posY), speedX(speedX), speedY(speedY), lifetime(lifetime)
  29.     {}
  30.     void MoveWithOnePos()
  31.     {
  32.         this->lifetime--;
  33.         this->x = x + speedX;
  34.         this->y = y + speedY;
  35.     }
  36.  
  37.     bool IsPossibleMoveWithOnePos_X()
  38.     {
  39.         return (this->x + speedX <= 65535 &&
  40.             this->x + speedX >= 0);
  41.     }
  42.     bool IsPossibleMoveWithOnePos_Y()
  43.     {
  44.         return (this->y + speedY <= 65535 &&
  45.             this->y + speedY >= 0);
  46.     }
  47.  
  48.     char getType()
  49.     {
  50.         return this->type;
  51.     }
  52.     int getX()
  53.     {
  54.         return this->x;
  55.     }
  56.     int getY()
  57.     {
  58.         return this->y;
  59.     }
  60.     int getSpeedX()
  61.     {
  62.         return this->speedX;
  63.     }
  64.     int getSpeedY()
  65.     {
  66.         return this->speedY;
  67.     }
  68.     int getLife()
  69.     {
  70.         return this->lifetime;
  71.     }
  72.     void setLife()
  73.     {
  74.         this->lifetime--;
  75.     }
  76. };
  77.  
  78. int main()
  79. {
  80.     cin.sync_with_stdio(false);
  81.     cout.sync_with_stdio(false);
  82.  
  83.     list<Point> li;
  84.     int totalNumber = 0;
  85.     int countA = 0;
  86.     int countM = 0;
  87.  
  88.     string strNum, line;
  89.     getline(cin, strNum);
  90.     std::string::size_type sz;   // alias of size_t
  91.     int num = std::stoi(strNum, &sz);
  92.     for (int i = 0; i < num; i++)
  93.     {
  94.         getline(cin, line);
  95.         istringstream iss(line);
  96.         int x, y, spX, spY, life;
  97.         char type;
  98.         iss >> type >> x >> y >> spX >> spY >> life;
  99.         li.push_back({ type, x, y, spX, spY, life });
  100.         if (type == 'a')
  101.         {
  102.             countA++;
  103.         }
  104.         if (type == 'm')
  105.         {
  106.             countM++;
  107.         }
  108.     }
  109.     //totalNumber = numberA + numberM;
  110.  
  111.     int steps;
  112.     cin >> steps;
  113.  
  114.     for (int i = 0; i < steps; i++)
  115.     {
  116.         int cntDeleated = 0;
  117.         for (auto it = li.begin(); it != li.end(); it++)
  118.         {
  119.             if (it->IsPossibleMoveWithOnePos_X() && it->IsPossibleMoveWithOnePos_Y())
  120.             {
  121.                 it->MoveWithOnePos();
  122.                 it->setLife();
  123.                 if (it->getLife() == 0)
  124.                 {
  125.                     if (it->getType() == 'a') { countA--; }
  126.                     if (it->getType() == 'm') { countM--; }
  127.                     li.erase(it);
  128.                     --it;
  129.                     cntDeleated++;
  130.                 }
  131.             }
  132.             else
  133.             {
  134.                 if (it->getType() == 'a') { countA--; }
  135.                 if (it->getType() == 'm') { countM--; }
  136.                 li.erase(it);
  137.                 --it;
  138.                 cntDeleated++;
  139.             }
  140.         }
  141.         //int r = 0, c = 0;
  142.         for (auto it = li.begin(); it != li.end(); it++)
  143.         {
  144.             for (auto ite = li.begin(); ite != li.end(); ite++)
  145.             {
  146.                 if (
  147.                     (it->getX() == ite->getX() &&
  148.                         it->getY() == ite->getY() &&
  149.                         it->getType() == 'a' &&
  150.                         ite->getType() == 'm') ||
  151.                         (it->getX() == ite->getX() &&
  152.                             it->getY() == ite->getY() &&
  153.                             it->getType() == 'm' &&
  154.                             ite->getType() == 'a')
  155.                     )
  156.                 {
  157.                     int xAni = it->getX();
  158.                     int yAni = it->getY();
  159.                     li.erase(it);
  160.                     --it;
  161.                     li.erase(ite);
  162.                     --ite;
  163.                     countA--;
  164.                     countM--;
  165.  
  166.                     for (auto iter = li.begin(); iter != li.end(); iter++)
  167.                     {
  168.                         if (iter->getX() == xAni &&
  169.                             iter->getY() == yAni)
  170.                         {
  171.                             if (iter->getType() == 'a') { countA--; }
  172.                             if (iter->getType() == 'm') { countM--; }
  173.                             li.erase(iter);
  174.                             --iter;
  175.                         }
  176.                     }
  177.                 }
  178.             }
  179.         }
  180.     }
  181.  
  182.     cout << countA << " " << countM << endl;
  183.     cout << countA + countM << endl;
  184.  
  185.     return 0;
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement