ens-ulm-1-2015

google hashcode 2015 source for team ens-ulm-1
git clone https://a3nm.net/git/ens-ulm-1-2015/
Log | Files | Refs

verifier.cpp (2486B)


      1 #include <vector>
      2 #include <cstdio>
      3 #include <algorithm>
      4 #include <map>
      5 #include <time.h>
      6 
      7 using namespace std;
      8 
      9 #define MAXN 302
     10 #define MAXL 2252
     11 #define NALT 10
     12 #define MAXT 402
     13 
     14 int R, C, A;
     15 int L, V, B, T;
     16 int rs, cs;
     17 
     18 struct Pt{
     19 	int r, c;
     20 	Pt(int r=0, int c=0) : r(r), c(c) {}
     21 };
     22 
     23 vector<int> coverage[MAXN][MAXN];
     24 
     25 Pt dest[NALT][MAXN][MAXN]; // where does the wind take us: -1 -1 = out
     26 
     27 Pt target[MAXL];
     28 
     29 bool covered[MAXL][MAXT]; // does someone cover target l at time t
     30 
     31 int columndist(int c1, int c2) {
     32 	return min(abs(c1 - c2), C - abs(c1 - c2));
     33 }
     34 
     35 int iscovered(int l, int r, int c) {
     36 	// does a loon at r c cover l?
     37 	if (l == -1 && r == -1)
     38 		return 0;
     39 	int u = target[l].r, v = target[l].c;
     40 	return ((r - u) * (r - u) + columndist(c, v) * columndist(c, v) <= V*V);
     41 }
     42 
     43 Pt position[MAXL];
     44 int alt[MAXL];
     45 
     46 int main(int argc, char **argv) {
     47 	FILE *input = fopen("final_round.in", "r");
     48 	fscanf(input, "%d%d%d", &R, &C, &A);
     49 	fscanf(input, "%d%d%d%d", &L, &V, &B, &T);
     50 	fscanf(input, "%d%d", &rs, &cs);
     51 	for (int i = 0; i < L; i++) {
     52 		int r, c;
     53 		fscanf(input, "%d%d", &r, &c);
     54 		target[i] = Pt(r, c);
     55 	}
     56 	for (int a = 0; a < A; a++)
     57 		for (int r = 0; r < R; r++)
     58 			for (int c = 0; c < C; c++) {
     59 				int dr, dc;
     60 				fscanf(input, "%d%d", &dr, &dc);
     61 				int destr, destc;
     62 				destr = r + dr;
     63 				destc = (c + dc + C) % C;
     64 				if (destr < 0 || destr >= R)
     65 					destr = destc = -1; // out
     66 				dest[a][r][c] = Pt(destr, destc);
     67 			}
     68 	//verifier
     69 	int score = 0;
     70 	for (int loon = 0; loon < B; loon++)
     71 		position[loon] = Pt(rs, cs);
     72 
     73 	for (int tour = 0; tour < T-1; tour++) {
     74 		for (int loon = 0; loon < B; loon++) {
     75 			int delta;
     76 			scanf("%d", &delta);
     77 			alt[loon] += delta;
     78 			if (alt[loon] == 0)
     79 				continue;
     80 			position[loon] = dest[alt[loon]-1][position[loon].r][position[loon].c];
     81 		}	
     82 
     83 		for (int target = 0; target < L; target++) {
     84 			bool cov = false;
     85 			for (int loon = 0; loon < B; loon++)
     86 				if (alt[loon] && iscovered(target, position[loon].r, position[loon].c))
     87 					cov = true;
     88 			if (cov)
     89 				score++;
     90 		}
     91 //*		//printing
     92 		char earth[MAXN][MAXN];
     93 		for (int r = 0; r < R; r++)
     94 			for (int c = 0; c < C; c++)
     95 				earth[r][c] = '.';
     96 
     97 		for (int l = 0; l < L; l++)
     98 			earth[target[l].r][target[l].c] = '#';
     99 
    100 		for (int b = 0; b < B; b++)
    101 			earth[position[b].r][position[b].c] = '0'+b;
    102 
    103 		for (int r = 0; r < R; r++) {
    104 			for (int c = 0; c < C; c++)
    105 				putchar(earth[r][c]);
    106 			printf("\n");
    107 		}
    108 		printf("\n"); 
    109 //		*/
    110 	}
    111 	printf("%d\n", score);
    112 	return 0;
    113 }
    114