Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

发个数据,这题感觉根本用不上并查集

Posted by bobten2008 at 2009-11-21 17:30:51 on Problem 1899
10 10
3
1 1 1
2 8 2
6 4 2
结果20
我就WA在了这种数据上

不需要并查集,一下是我程序的框架:
bool change = true;
while(change)
{
	change = false;
	for(i = 1; i < num; i++)
	{
		if(recs[i].unvalid) continue; //表示这个矩形已经合并到其他矩形里去了,不需要再处理
		for(j = 1; j <= num; j++)
		{
			if(i == j || recs[j].unvalid) continue;
			//判断两个矩形是否相交或者包含,则更新recs[j]的数据形成更大的矩形
                        if(cross(recs[i], recs[j]))
			{
				change = true;
				recs[i].unvalid = true;
				break;
			}
		}
	}
}
最后再扫描一遍,如果recs[i].unvalid = false就从总面积中减去这个矩形的面积即可

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator