Cod sursa(job #541801)

Utilizator sodamngoodSo Damn Good sodamngood Data 25 februarie 2011 14:31:54
Problema Walls Scor 30
Compilator cpp Status done
Runda Romanian Master in Mathematics and Sciences 2011, Ziua 1 Marime 1.41 kb
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 7010
#define LL long long

int N, M;
int shots[maxn][maxn];
struct Turn {
    LL X, H, W;
} T[maxn];

FILE *f2;

void check(LL x, LL y) {
    int i, j, p, q;

    for(i=N; i>=1; i--) {
         if(T[i].X + T[i].W <= x) {
              //turn bun, vad daca pot sa trag
              if(T[i].H >= y) {
                   //pot sa trag
                   shots[i][y] ++;
                   int val = T[i].X + T[i].W - shots[i][y];
                   fprintf(f2, "HIT %d %d ", val, i);

                   if(shots[i][y] == T[i].W) {
                        //acesta a fost ultimul nivel
                        fprintf(f2, "YES\n");
                        T[i].H = y - 1;
                   }
                   else {
                        fprintf(f2, "NO\n");
                   }

                   return;
              }
         }
    }

    fprintf(f2, "MISS\n");
}

int main() {
    FILE *f1=fopen("walls.in", "r"); f2=fopen("walls.out", "w");
    int i, j; LL p, q;

    fscanf(f1, "%d\n", &N);
    LL lst = 1;
    for(i=1; i<=N; i++) {
         fscanf(f1, "%lld %lld\n", &p, &q);
         T[i].X = lst; T[i].W = p;
         lst = lst + p + 1;
         T[i].H = q;
    }

    fscanf(f1, "%d\n", &M);
    for(i=1; i<=M; i++) {
         fscanf(f1, "%lld %lld\n", &p, &q);

         check(p, q);
    }

    fclose(f1); fclose(f2);
    return 0;
}