Skip to content

Instantly share code, notes, and snippets.

@ellemedit
Last active October 2, 2016 10:42
Show Gist options
  • Save ellemedit/6f42e76b9a1a9327ac12165c8cbaca6b to your computer and use it in GitHub Desktop.
Save ellemedit/6f42e76b9a1a9327ac12165c8cbaca6b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <limits.h>
// paper color
#define WHITE 0
#define BLACK 1
class Paper {
private:
int x, y, size;
int width, height;
int color;
public:
Paper() {
this->x = this->y = this->size = 0;
this->color = WHITE;
}
int getSize() {
return this->size;
}
void setSize(int width, int height) {
this->width = width;
this->height = height;
this->size = width * height;
}
bool checkCollision(int x, int y) {
return (
this->x < x &&
this->x + width > x &&
this->y < y &&
this->y + height > y
);
}
void divide(int x, int y, Paper *dividedPaper) {
dividedPaper->x = this->x;
dividedPaper->y = this->y;
if (this->color == WHITE) {
int height = this->height - (y - this->y);
dividedPaper->height = this->height - height;
this->height = height;
dividedPaper->width = this->width;
this->y = y;
this->color = dividedPaper->color = BLACK;
} else {
int width = this->width - (x - this->x);
dividedPaper->width = this->width - width;
this->width = width;
dividedPaper->height = this->height;
this->x = x;
this->color = dividedPaper->color = WHITE;
}
this->size = this->width * this->height;
dividedPaper->size = dividedPaper->width * dividedPaper->height;
}
};
Paper papers[30001];
int main() {
// default paper size
int width, height;
// number of points
int n;
// get input
scanf("%d %d %d", &width, &height, &n);
// initialize blank paper
papers[0].setSize(width, height);
// make division and find smallest and largest paper
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d %d", &x, &y);
// find paper which point is on
for (int j = 0; j < i; j++) {
Paper *paper = papers + j;
if (paper->checkCollision(x, y)) {
Paper *dividedPaper = papers + i;
paper->divide(x, y, dividedPaper);
break;
}
}
}
int minSize = INT_MAX, maxSize = INT_MIN;
for (int i = 0; i <= n; i++) {
int size = papers[i].getSize();
if (size < minSize) {
minSize = size;
}
if (size > maxSize) {
maxSize = size;
}
}
printf("%d %d", maxSize, minSize);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment