第一题:楼层(floor)
暴力,把楼层数字拆分,如果与t相等,则ans– continue。水题来的。
代码:
var m,t,ans,s,i,fuck:longint;
f:boolean;
begin
assign(input,'floor.in');
assign(output,'floor.out');
reset(input);
rewrite(output);
read(m,t);
for i:=1 to m do
begin
s:=i; f:=false;
while s>0 do
begin
fuck:=s mod 10;
if fuck=t then break;
s:=s div 10;
if s=0 then f:=true;
end;
if f then inc(ans);
end;
write(ans);
close(input);
close(output);
end.
第二题:朋友(friend)
将其中一种人排个序,枚举另一种人,对后者二分查找能力值恰好小于他的。
代码:
var a,b:array[-10..20011] of longint;
i,ans,n,m,t:longint;
procedure sort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l; j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do i:=i+1;
while x<a[j] do j:=j-1;
if not(i>j) then
begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
i:=i+1; j:=j-1;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
function f(x,l,r:longint):longint;
var s,mid:longint;
begin
s:=0;
while l<=r do
begin
mid:=(l+r) div 2;
if x>a[mid] then begin s:=mid; l:=mid+1; end else r:=mid-1;
end;
exit(s);
end;
begin
assign(input,'friend.in');
assign(output,'friend.out');
reset(input);
rewrite(output);
read(m,n);
for i:=1 to m do read(b[i]); for i:=1 to n do read(a[i]); sort(1,n);
ans:=0 ;
for i:=1 to m do ans:=ans+f(b[i],1,n);
write(ans);
close(input);
close(output);
end.
第三题 侦察兵
数据10是极限数据,用来卡纯暴力的(记忆化也不行)。
利用矩阵前缀和,求出那个区间,瞬间变水!!!
ans=sum[n,n]-sum[x,n]-sum[n,y]+sum[x,y]+sum[x-1,y-1];
第四题 遭遇战
技艺高超的模拟,详见程序——————