Skip to content

Instantly share code, notes, and snippets.

@brooksbp
Created May 21, 2013 21:54
Show Gist options
  • Save brooksbp/5623586 to your computer and use it in GitHub Desktop.
Save brooksbp/5623586 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
#define DEAD_PIXEL 1
char monitor[40000][40000];
void mark_dead(int x, int y) {
if ((x >= 0 && x < 40000) && (y >= 0 && y < 40000)) {
monitor[x][y] = DEAD_PIXEL;
}
}
int main() {
int n; cin >> n;
for (int t = 0; t < n; t++) {
memset(monitor, 0, sizeof(monitor[0][0]) * 40000 * 40000);
int W, H, P, Q, N, X, Y, a, b, c, d;
cin >> W >> H >> P >> Q >> N >> X >> Y >> a >> b >> c >> d;
vector<int> x; x.push_back(X);
vector<int> y; y.push_back(Y);
mark_dead(x.back(), y.back());
for (int i = 1; i < N; i++) {
int xx = ((x.back() * a) + (y.back() * b) + 1) % W;
int yy = ((x.back() * c) + (y.back() * d) + 1) % H;
x.push_back(xx);
y.push_back(yy);
mark_dead(xx, yy);
}
for (int i = 0; i < x.size(); i++) {
for (int xx = P-1; xx >= 0; xx--) {
if (!(x[i] - xx >= 0)) continue;
for (int yy = Q-1; yy >= 0; yy--) {
if (!(y[i] - yy >= 0)) continue;
mark_dead(x[i] - xx, y[i] - yy);
}
}
}
int locations = 0;
for (int i = 0; i <= (W - P); i++) {
for (int j = 0; j <= (H - Q); j++) {
locations += (monitor[i][j] != DEAD_PIXEL);
}
}
cout << "Case #" << (t+1) << ": " << locations << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment