Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
发个数据,这题感觉根本用不上并查集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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator