Cow Crossings
Posted godrose
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cow Crossings相关的知识,希望对你有一定的参考价值。
题面:
思路:
求非逆序对的个数
代码:
var n,i,j,ans,k:longint; a,b:Array[0..100005] of longint; f:array[0..100005] of boolean; procedure sort(l,r: longint); var i,j,x,y: longint; begin i:=l; j:=r; x:=b[(l+r) div 2]; repeat while b[i]<x do inc(i); while x<b[j] do dec(j); if not(i>j) then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; y:=b[i]; b[i]:=b[j]; b[j]:=y; inc(i); j:=j-1; end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; begin assign(input,‘crossings.in‘); reset(input); assign(output,‘crossings.out‘); rewrite(output); read(n); for i:=1 to n do read(a[i],b[i]); sort(1,n); k:=-maxlongint; for i:=1 to n do if k>a[i] then f[i]:=true else k:=a[i]; k:=maxlongint; for i:=n downto 1 do if k<a[i] then f[i]:=true else k:=a[i]; ans:=0; for i:=1 to n do if f[i] then inc(ans); writeln(n-ans); close(input);close(output); end.
以上是关于Cow Crossings的主要内容,如果未能解决你的问题,请参考以下文章