首页 > 代码库 > NOIP2011

NOIP2011

DAY1

铺地毯
(carpet.cpp/c/pas)

模拟

倒序离线处理

技术分享
 1 program carpet;
 2 var
 3   l,w:array[0..10000,1..2] of longint;
 4   n,i,a,b,g,k,x,y:longint;
 5   flag:boolean;
 6 begin
 7 assign(input,carpet.in);
 8 reset(input);
 9 assign(output,carpet.out);
10 rewrite(output);
11   readln(n);
12   for i:=1 to n do
13    begin
14      readln(a,b,g,k);
15      l[i,1]:=a;
16      l[i,2]:=a+g;
17      w[i,1]:=b;
18      w[i,2]:=b+k;
19    end;
20   readln(x,y);
21   flag:=true;
22   for i:=n downto 1 do
23    if (l[i,1]<=x)and(x<=l[i,1]) and (w[i,1]<=y)and(y<=w[i,2]) then
24     begin writeln(i); flag:=false; break; end;
25   if flag then writeln(-1);
26 close(input);
27 close(output);
28 end.
我今年的程序
技术分享
 1 var
 2   n,i,g,k,x,y:longint;
 3   a,b,c,d:array[1..10000] of longint;
 4 begin
 5 assign(input,carpet.in);
 6 reset(input);
 7 assign(output,carpet.out);
 8 rewrite(output);
 9   readln(n);
10   for i:=1 to n do
11    begin
12      readln(a[i],b[i],g,k);
13      c[i]:=a[i]+g;
14      d[i]:=b[i]+k;
15    end;
16   readln(x,y);
17   for i:=n downto 1 do
18    if (x>=a[i]) and (x<=c[i]) and (y>=b[i]) and (y<=d[i])
19     then begin writeln(i); close(input); close(output); halt; end;
20   writeln(-1);
21 close(input);
22 close(output);
23 end.
24 
25 program P620;
26 var
27   x,y,n,a1,b1,i,j,s:longint;
28   a,b,c,d:array[1..10000] of longint;
29 begin
30 assign(input,carpet.in);
31 reset(input);
32 assign(output,carpet.out);
33 rewrite(output);
34   readln(n);
35   for i:=1 to  n do
36   begin
37     readln(a[i],b[i],a1,b1);
38     c[i]:=a[i]+a1;
39     d[i]:=b[i]+b1;
40   end;
41   readln(x,y);
42   s:=-1;
43    for i:=1 to n do
44     if (a[i]<=x)and(b[i]<=y)and(c[i]>=x)and(d[i]>=y) then s:=i;
45    writeln(s);
46 end.
我以前的程序

 

 

 

NOIP2011