Pagini recente » Cod sursa (job #2734175) | Cod sursa (job #1934675) | Cod sursa (job #2342145) | Cod sursa (job #1472026) | Cod sursa (job #541788)
Cod sursa(job #541788)
// 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;
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(int it=nrWalls-1;it>=0;it--)
if(wall[it].x + wall[it].width <= x && wall[it].height >= y) {
int counter = 1;
ok = true;
counter = count(wall[it].damaged.begin(),wall[it].damaged.end(),y);
// daca e feliat zidul
if(counter + 1 == wall[it].width) {
wall[it].height = wall[it].height - (wall[it].height - y);
out << "HIT " << wall[it].x+wall[it].width-counter-1 << " " << it+1 << " " << "YES\n";
}
else {
wall[it].damaged.push_back(y);
out << "HIT " << wall[it].x+wall[it].width-counter-1 << " " << it+1 << " " << "NO\n";
}
break;
}
if(!ok)
out << "MISS\n";
}
/* int a:3;
a = 4;
out << a;*/
in.close();
out.close();
}