最简单的区间贪心,但是考察细心。
注意事项:
1、考虑s>t的情况
2、读入的时候要把s、t分别转换为(s+1)div 2和(t+1)div 2
代码:
Program poj1083;//By_ThispoetConst maxn=200;Var t,i,j,k,m,n :Longint; heap,l,r :Array[1..maxn*2]of Longint; heap_size :Longint; Procedure Down(i:Longint);var j:Longint;begin while ((i<<1)<=heap_size) do begin j:=i<<1; if (jheap[j+1])then inc(j); if heap[j] 1) do begin j:=i>>1; if heap[j]>heap[i] then begin heap[i]:=heap[i] xor heap[j]; heap[j]:=heap[i] xor heap[j]; heap[i]:=heap[i] xor heap[j]; i:=j; end else break; end;end; Procedure Qsort(ll,rr:Longint);var i,j,k,temp:Longint;begin i:=ll;j:=rr; k:=l[i+random(j-i+1)]; repeat while l[i] k do dec(j); if i<=j then begin temp:=l[i];l[i]:=l[j];l[j]:=temp; temp:=r[i];r[i]:=r[j];r[j]:=temp; inc(i);dec(j); end; until i>j; if ll 0 do begin heap_size:=0; readln(n); for i:=1 to n do begin readln(l[i],r[i]); if l[i]>r[i] then Swap(l[i],r[i]); l[i]:=(l[i]+1)>>1; r[i]:=(r[i]+1)>>1; end; Qsort(1,n); for i:=1 to n do begin if (heap_size>0)and(heap[1]