Pagini recente » Cod sursa (job #72066) | Cod sursa (job #172953) | Cod sursa (job #2574175) | Cod sursa (job #2012524) | Cod sursa (job #541764)
Cod sursa(job #541764)
// http://infoarena.ro/problema/walls
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("walls.in");
ofstream out("walls.out");
struct stuff {
int x;
int width;
int height;
vector<int> damaged;
};
int nrWalls,nrAttacks;
vector<stuff> wall;
void readWalls();
void procesAttacks();
bool comp(stuff one,stuff two) {
return one.height < two.height;
}
int main() {
readWalls();
procesAttacks();
return (0);
}
void readWalls() {
int currentWidth;
stuff tmp;
in >> nrWalls;
tmp.x = 1;
in >> tmp.width;
in >> tmp.height;
wall.push_back(tmp);
for(int i=1;i<nrWalls;i++) {
in >> currentWidth;
tmp.x += currentWidth + 1;
in >> tmp.height;
wall.push_back(tmp);
}
}
void procesAttacks() {
in >> nrAttacks;
int x,y;
bool ok = false;
vector<stuff>::reverse_iterator it;
int maxHeight;
stuff tmp;
tmp = *max_element(wall.begin(),wall.end(),comp);
maxHeight = tmp.height;
for(int i=1;i<=nrAttacks;i++) {
in >> x >> y;
ok = false;
if( y <= maxHeight)
for(it=wall.rbegin();it!=wall.rend();++it)
if(it->x + it->width <= x && it->height >= y) {
int counter = 1;
ok = true;
counter = count(it->damaged.begin(),it->damaged.end(),y);
// daca e feliat zidul
if(counter + 1 == it->width) {
it->height = it->height - (it->height - y);
out << "HIT " << it->x+it->width-counter-1 << " " << y << " " << "YES\n";
}
else {
it->damaged.push_back(y);
out << "HIT " << it->x+it->width-counter-1 << " " << y << " " << "NO\n";
}
break;
}
if(!ok)
out << "MISS\n";
}
}