首先要知道一次打掉一个1*x*y的面是最优的。证明太简单所以略。
然后看这道题的二维版本:bzoj1693 [Usaco2007 Demo]Asteroids
然后这样的题一般都是一维暴力来减少一维。就枚举最小的一维打掉哪些面。然后把剩下的压成两维,然后做。
RunID | User | Problem | Result | Memory | Time | Language | Code_Length | Submit_Time |
410333 | Accepted | 12032 kb | 4 ms | / | 862 B | 2013-05-11 20:51:11 |
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 var 2 u,v,k,ans,i,j,n,a,ee:longint; 3 link:Array[0..2002]of longint; 4 next,head,e:array[0..1000000]of longint; 5 b:array[0..20002]of longint; 6 procedure add(u,v:longint); 7 begin 8 inc(ee); 9 next[ee]:=head[u];10 head[u]:=ee;11 e[ee]:=v;12 end;13 14 function find(x:longint):boolean;15 var j:longint;16 begin17 j:=head[x];18 while j<>0 do19 begin20 if b[e[j]]<>i then21 begin22 b[e[j]]:=i;23 if (link[e[j]]=0) or (find(link[e[j]])) then24 begin25 link[e[j]]:=x;26 exit(true);27 end;28 end;29 j:=next[j];30 end;31 exit(false);32 end;33 begin34 readln(n,k);35 for i:=1 to k do36 begin37 readln(u,v);38 add(u,v);39 end;40 for i:=1 to n do41 if find(i) then inc(ans);42 writeln (ans);43 end.