hdu 1264

本来想用线段树做的,仔细看题发现题目数据太弱了,直接用一个数组标记平面上每一个单位方格即可,水题~

/*
* hdu1264/linux.cpp
* Created on: 2011-9-1
* Author : ben
*/
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<cmath>
#include
<algorithm>
using namespace std;

const int MAX_COR = 105;

bool map[MAX_COR][MAX_COR];

void work() {
int t, xi, yi, xa, ya;
while (true) {
memset(map,
false, sizeof(map));
while (true) {
scanf(
"%d%d%d%d", &xi, &yi, &xa, &ya);
if (xi == -1 && yi == -1 && xa == -1 && ya == -1) {
break;
}
if (xi == -2 && yi == -2 && xa == -2 && ya == -2) {
break;
}
if (xi > xa) {
t
= xi;
xi
= xa;
xa
= t;
}
if (yi > ya) {
t
= yi;
yi
= ya;
ya
= t;
}
for (int i = xi; i < xa; i++) {
for (int j = yi; j < ya; j++) {
map[i][j]
= true;
}
}
}
t
= 0;
for (int i = 0; i < MAX_COR; i++) {
for (int j = 0; j < MAX_COR; j++) {
t
+= map[i][j];
}
}
printf(
"%d\n", t);
if (xi == -2 && yi == -2 && xa == -2 && ya == -2) {
break;
}
}
}

int main() {
#ifndef ONLINE_JUDGE
freopen(
"data.in", "r", stdin);
#endif
work();
return 0;
}
posted @ 2011-09-01 14:50  moonbay  阅读(179)  评论(0编辑  收藏  举报