POJ1083 Moving Tables--heap+욕심--pku1083
2115 단어 table
참고 사항:
1、s>t의 상황을 고려
2. 읽을 때 s, t를 각각 (s+1)div2와 (t+1)div2로 변환해야 한다.
코드:
Program poj1083;//By_Thispoet
Const
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 (j<heap_size)and(heap[j]>heap[j+1])then inc(j);
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 Up(i:Longint);
var j:Longint;
begin
while (i>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 inc(i);
while l[j]>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<j then Qsort(ll,j);
if i<rr then Qsort(i,rr);
end;
Procedure Swap(var i,j:Longint);
begin
i:=i xor j;
j:=i xor j;
i:=i xor j;
end;
BEGIN
readln(t);
randomize;
while t>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]<l[i])then
begin
heap[1]:=r[i];
Down(1);
end else
begin
inc(heap_size);
heap[heap_size]:=r[i];
Up(heap_size);
end;
end;
writeln(heap_size*10);
dec(t);
end;
END.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Vuetify에서 행 그룹화이 기사에서는 유사한 값으로 테이블의 행을 그룹화하는 방법에 대한 경험을 공유하고자 합니다. 물론 기본 그룹화 예제를 찾을 수 있지만 제 사용 사례에는 약간의 고급 기능이 필요했습니다. 제품 데이터가 있다고 가정합니...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.