Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 01_04_Task4_Antimatter.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream> //for std::cout
- #include <string>
- #include <sstream>
- #include <iomanip>
- #include <vector>
- #include <utility> //pair<vey, value>
- #include<list>
- using namespace std;
- class Point
- {
- private:
- char type;
- int x;
- int y;
- int speedX;
- int speedY;
- int lifetime;
- public:
- Point()
- {}
- Point(char type, int posX, int posY, int speedX, int speedY, int lifetime) :
- type(type), x(posX), y(posY), speedX(speedX), speedY(speedY), lifetime(lifetime)
- {}
- void MoveWithOnePos()
- {
- this->lifetime--;
- this->x = x + speedX;
- this->y = y + speedY;
- }
- bool IsPossibleMoveWithOnePos_X()
- {
- return (this->x + speedX <= 65535 &&
- this->x + speedX >= 0);
- }
- bool IsPossibleMoveWithOnePos_Y()
- {
- return (this->y + speedY <= 65535 &&
- this->y + speedY >= 0);
- }
- char getType()
- {
- return this->type;
- }
- int getX()
- {
- return this->x;
- }
- int getY()
- {
- return this->y;
- }
- int getSpeedX()
- {
- return this->speedX;
- }
- int getSpeedY()
- {
- return this->speedY;
- }
- int getLife()
- {
- return this->lifetime;
- }
- void setLife()
- {
- this->lifetime--;
- }
- };
- int main()
- {
- cin.sync_with_stdio(false);
- cout.sync_with_stdio(false);
- list<Point> li;
- int totalNumber = 0;
- int countA = 0;
- int countM = 0;
- string strNum, line;
- getline(cin, strNum);
- std::string::size_type sz; // alias of size_t
- int num = std::stoi(strNum, &sz);
- for (int i = 0; i < num; i++)
- {
- getline(cin, line);
- istringstream iss(line);
- int x, y, spX, spY, life;
- char type;
- iss >> type >> x >> y >> spX >> spY >> life;
- li.push_back({ type, x, y, spX, spY, life });
- if (type == 'a')
- {
- countA++;
- }
- if (type == 'm')
- {
- countM++;
- }
- }
- //totalNumber = numberA + numberM;
- int steps;
- cin >> steps;
- for (int i = 0; i < steps; i++)
- {
- int cntDeleated = 0;
- for (auto it = li.begin(); it != li.end(); it++)
- {
- if (it->IsPossibleMoveWithOnePos_X() && it->IsPossibleMoveWithOnePos_Y())
- {
- it->MoveWithOnePos();
- it->setLife();
- if (it->getLife() == 0)
- {
- if (it->getType() == 'a') { countA--; }
- if (it->getType() == 'm') { countM--; }
- li.erase(it);
- --it;
- cntDeleated++;
- }
- }
- else
- {
- if (it->getType() == 'a') { countA--; }
- if (it->getType() == 'm') { countM--; }
- li.erase(it);
- --it;
- cntDeleated++;
- }
- }
- //int r = 0, c = 0;
- for (auto it = li.begin(); it != li.end(); it++)
- {
- for (auto ite = li.begin(); ite != li.end(); ite++)
- {
- if (
- (it->getX() == ite->getX() &&
- it->getY() == ite->getY() &&
- it->getType() == 'a' &&
- ite->getType() == 'm') ||
- (it->getX() == ite->getX() &&
- it->getY() == ite->getY() &&
- it->getType() == 'm' &&
- ite->getType() == 'a')
- )
- {
- int xAni = it->getX();
- int yAni = it->getY();
- li.erase(it);
- --it;
- li.erase(ite);
- --ite;
- countA--;
- countM--;
- for (auto iter = li.begin(); iter != li.end(); iter++)
- {
- if (iter->getX() == xAni &&
- iter->getY() == yAni)
- {
- if (iter->getType() == 'a') { countA--; }
- if (iter->getType() == 'm') { countM--; }
- li.erase(iter);
- --iter;
- }
- }
- }
- }
- }
- }
- cout << countA << " " << countM << endl;
- cout << countA + countM << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement