vj1008 篝火晚会

Vj1008 篝火晚会

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //´ËÌâÒƶ¯±àºÅ²¢²»ÊÇÁ¬ÐøµÄ m ¸ö£¡ //±ÉÈ˵ķ½·¨ //¹¹Ôì»· ¹¹Ôì²»³öÀ´ÔòÊä³ö -1 //×îÉÙÒƶ¯´ú¼ÛΪ²»ÔÚλÖõÄÔªËظöÊý //ÒòΪÊÇ»· ËùÒÔ¿ÉÒÔ n ´Îö¾Ù¶Ï¿ªÎ»Öà ´ ´ÔÓ¶È O(n^2) ³¬Ê± ÔÙÒ»Ò»ÕÒ¶ÔÓ¦µÄ×î¶àÔªËصĸöÊý ÕâÑùʱ¼ä¸ //ÒòΪÎÞÂÛÔõÑù¶Ï¿ª »·ÖÐÔªËصÄÏà¶ÔλÖö¼²»±ä //ËùÒÔ¿ÉÒÔͳ¼Æ ÐÂÐòÁÐÖеÄÔªËض¼½ÏÔÀ´×óÒÆÁ˼¸Î» ´Î»ÖÃ×î¶àµÄÔªËظöÊý //ÔÙ°ÑÐòÁз¹ýÀ´ÔÙ×öÒ»±é ¹ //±ÉÈ˵ÄÎÊÌâ //ÓÖÍüÁË·¶Î§... / //ͳ¼Æ×óÒÆÁ˼¸Î»ÒªÓà mod const maxn=50000; var n,m,ans:longint; x,y,d:array[0..maxn] of longint; a:array[0..1,0..maxn] of longint; procedure out; begin writeln(-1); halt; end; ±»Í³¼ÆµÄ×î¶àµÄÄǸö²î¶ÔÓ¦×ÅÔÚÔÀ procedure init; var i:longint; begin readln(n); for i:=1 to n do begin readln(x[i],y[i]); if (x[i]=i) or (y[i]=i) or (x[i]=y[i]) then out; end; end; procedure calc(t:integer); var i,j:longint; begin fillchar(d,sizeof(d),0); for i:=1 to n do begin j:=(a[t,i]-i+n) mod n; inc(d[j]); if n-d[j]<ans then ans:=n-d[j]; end; end; procedure main; var i,j:longint; begin m:=1; a[0,1]:=1; i:=x[1]; while m<n do begin if (x[i]<>a[0,m]) and (y[i]<>a[0,m]) then out; inc(m); a[0,m]:=i; if x[i]=a[0,m-1] then i:=y[i] else i:=x[i]; end; for i:=n downto 1 do a[1,n-i+1]:=a[0,i]; ans:=maxlongint; calc(0); calc(1); end; procedure print; begin writeln(ans); end; begin init; main; print; end. ...
View Full Document

This note was uploaded on 02/21/2011 for the course CS 001 taught by Professor 001 during the Spring '11 term at Shandong University.

Page1 / 2

Vj1008 &ccedil;&macr;&ccedil;&laquo;&aelig;™š&auml;&frac14;š

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online