Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求错帖...

Posted by lr_bob at 2012-04-18 11:32:14 on Problem 2373
大神啊......交了n次了...
code
Program poj2373;

var
	n,m:longint;
	a,b,bg,ed,k,i,h,t,p:longint;
	f,q		:Array[0..1000001] of longint;
	g		:Array[0..1000001] of boolean;
begin
	readln(n,m);
	readln(a,b);
	for i:=1 to n do 
		begin
			readln(bg,ed);
			for k:=bg+1 to ed-1 do g[k]:=true; 
		end;
	for i:=1 to m do f[i]:=1<<30;
	f[0]:=0; h:=1; t:=1; q[1]:=0;
	for i:=a to m>>1 do	
		begin
			p:=i<<1;
			if g[p] then continue;
			while (h<t) and (q[h]<p-(b<<1)) do inc(h);
			if q[h]>p-(a<<1) then continue;
			f[p]:=f[q[h]]+1;
			while (h<t) and (f[q[t]]>f[p]) do dec(t);
			inc(t); q[t]:=p;
		end;
	if f[m]=1<<30 then writeln(-1) else writeln(f[m]);
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator