Cod sursa(job #541740)

Utilizator feelshiftFeelshift feelshift Data 25 februarie 2011 13:48:37
Problema Walls Scor 0
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 1 Marime 2 kb
// http://infoarena.ro/problema/walls
#include <fstream>
#include <vector>
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();

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;
    vector<int>::iterator dit;

    for(int i=1;i<=nrAttacks;i++) {
        in >> x >> y;
        ok = false;

        for(it=wall.rbegin();it!=wall.rend();++it)
            if(it->x + it->width <= x && it->height >= y) {
                int counter = 1;
                ok = true;

                for(dit=it->damaged.begin();dit!=it->damaged.end();++dit)
                    if(*dit == y)
                        counter++;

                // daca e feliat zidul
                if(counter == it->width) {
                    /*for(dit=it->damaged.begin();dit!=it->damaged.end();++dit)
                        if(*dit >= y)
                            it->damaged.erase(dit);*/

                    it->height = it->height - (it->height - y);
                    out << "HIT " << it->x+it->width-counter << " " << y << " " << "YES\n";
                }
                else {
                    it->damaged.push_back(y);
                    out << "HIT " << it->x+it->width-counter << " " << y << " "<< "NO\n";
                }

                break;
            }

        if(!ok)
            out << "MISS\n";
    }
}