比赛 20161116 评测结果 AAAAAAAAAA
题目名称 删除他们! 最终得分 100
用户昵称 Tabing010102 运行时间 0.003 s
代码语言 C++ 内存使用 0.29 MiB
提交时间 2016-11-16 09:17:54
显示代码纯文本
#include <cstdio>
using namespace std;
typedef long long LL;
FILE *fin, *fout;
int n, m, q;
LL left;
inline int min(int a, int b) { return a<b?a:b; }
inline int max(int a, int b) { return a<b?b:a; }
int main() {
	fin = fopen("deleteit.in", "r");
	fout = fopen("deleteit.out", "w");
	fscanf(fin, "%d%d%d", &n, &m, &q);
	left = n*m;
	int Ln=n, Col=m;
	//Ln行,Col列
	for(int i = 1; i <= q; i++) {
		int x1, y1, x2, y2, xi1, xi2, yi1, yi2;
		fscanf(fin, "%d%d%d%d", &xi1, &yi1, &xi2, &yi2);
		xi1++,yi1++,xi2++,yi2++;
		x1 = min(xi1, xi2); y1 = min(yi1, yi2);
		x2 = max(xi1, xi2); y2 = max(yi1, yi2);
		if(Ln < x1) {//框里没有文件
			continue;
		} else if(Ln==x1 && Col<y1) {//框里没有文件
			continue;
		} else if((Ln>x2) || (Ln==x2 && Col>=y2)) {//框里全部是文件
			left -= (x2-x1+1)*(y2-y1+1);
			Ln = left/m;
			Col = left-m*Ln;
			if(Col == 0) Col = m;
			else Ln++;
		} else {
			if(Col >= y2) {//第Ln一行完全包含
				left -= (Ln-x1+1)*(y2-y1+1);
			} else if(Col < y1) {//第Ln行完全不包含
				left -= (Ln-1-x1+1)*(y2-y1+1);
			} else {//第Ln行不完全包含
				left -= (Ln-1-x1+1)*(y2-y1+1);;
				left -= Col-y1+1;
			}
			Ln = left/m;
			Col = left-m*Ln;
			if(Col == 0) Col = m;
			else Ln++;
		}
	}
	fprintf(fout, "%lld\n", left);
	return 0;
}