vijos p1091(环球旅行)

模拟,单纯模拟会超时,但是有个定理:若从此地发现没油,则不必从头开始搜,直接从当前地开始就可以了。

 1 program P1091;
 2 var
 3         n,m,i,j,k,l,l2,h,q,x,w:longint;
 4         s,pow,ha:array[1..600000] of longint;
 5         bool:boolean;
 6 begin
 7         read(n,l);
 8         l2:=l;
 9         for i:=1 to n do
10                 begin
11                 read(s[i],pow[i]);
12                 if s[i]<=pow[i-1] then begin inc(h); ha[h]:=i-1; end;
13                 end;
14         if s[1]<=pow[n] then begin inc(h); ha[h]:=n end;
15         for i:=2 to n do
16                 l2:=l2-s[i];
17         s[1]:=l2;
18         i:=0;q:=0;
19         repeat
20                 bool:=true;
21                 inc(q);
22                 i:=q;
23                 x:=pow[i];
24                 while(((x>=s[i+1])and(i<n))or((x>=s[1]) and (i=n)))and(bool)do
25                         begin
26                         inc(i);
27                         if i=n+1 then i:=1;
28                         x:=x-s[i]+pow[i];
29                         if i=q
30                         then begin bool:=false; write(q,' '); w:=1;end;
31                         end;
32                if bool then if i>q then q:=i-1;
33         until (q=n);
34         {if w=0 then write('-1');}
35 end.  

转载于:https://www.cnblogs.com/zyxx233/archive/2012/10/14/2723395.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值