题目地址:http://poj.org/problem?id=1899
int nCount = 0;
cin>>nCount;
while (nCount--)
{
int x, y, r;
cin>>x>>y>>r;
dqSrcRect.push_back(CreateRect(x, y, r));
}
while (!dqSrcRect.empty())
{
LPRECT pRect1 = dqSrcRect.begin();
LPRECT pRect2 = dqDstRect.begin();
bool bChanged = false;
while (pRect2 != dqDstRect.end())
{
if (IntersectRect(pRect1, pRect2))
{
dqDstRect.erase(pRect2); // 清除目的队列中能合并的矩形
bChanged = true;
break;
}
++pRect2;
}
if (!bChanged) // 没有交集
{
dqDstRect.push_back(*pRect1);
dqSrcRect.pop_front();
}
}
int iRemainSize = nWidth * nHeight;
for (LPRECT pRect = dqDstRect.begin();
pRect != dqDstRect.end(); pRect++)
{
iRemainSize -= (pRect->right - pRect->left) * (pRect->bottom - pRect->top);
}
cout<<iRemainSize;
return 0;
}