consolidate all repos to one for archive
This commit is contained in:
72
semester_5/aturp/naloga_3/main.cpp
Normal file
72
semester_5/aturp/naloga_3/main.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
struct pillow
|
||||
{
|
||||
int x, y, s;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::ifstream in(argv[1]);
|
||||
if (!in.is_open())
|
||||
{
|
||||
std::cout << "Error opening file" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
int N, V, S;
|
||||
in >> N >> V >> S;
|
||||
|
||||
std::vector<std::multiset<int>> columns(S);
|
||||
char c;
|
||||
int row;
|
||||
std::vector<pillow> pillows;
|
||||
pillows.reserve(N);
|
||||
pillow p;
|
||||
int max_fall = 0;
|
||||
|
||||
for (size_t i = 0; i < N; i++)
|
||||
{
|
||||
in >> c;
|
||||
if (c == '+')
|
||||
{
|
||||
in >> p.x >> p.y >> p.s;
|
||||
p.s--;
|
||||
pillows.push_back(p);
|
||||
for (int j = p.y; j <= p.y + p.s; j++)
|
||||
{
|
||||
columns[j].insert(p.x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
in >> row;
|
||||
pillow p = pillows[row - 1];
|
||||
for (int j = p.y; j <= p.y + p.s; j++)
|
||||
{
|
||||
columns[j].erase(columns[j].find(p.x));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &i : columns)
|
||||
{
|
||||
auto it = i.begin();
|
||||
if (it == i.end())
|
||||
{
|
||||
max_fall = V;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*it > max_fall)
|
||||
max_fall = *it;
|
||||
}
|
||||
}
|
||||
std::cout << max_fall << std::endl;
|
||||
max_fall = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user