[HJOI]19.11.8模拟赛
2019题目
19.11.8模拟赛
【题目描述】
【样例输出】
【数据范围】
对于
对于
解析:
明显的水题,每一位逐位处理,每一次结果就是上一次的余数乘以
用
故此题可以
var
a:ansistring;
ans,i:longint;
begin
assign(input,'a.in');reset(input);
assign(output,'a.out');rewrite(output);
readln(a);
for i:=1 to length(a) do
begin
ans:=ans*10+(ord(a[i])-48);
ans:=ans mod 7;
end;
writeln(ans);
close(input);
close(output);
end.
【题目描述】
小
一天,小
保证答案的个数不超过
【输入数据】
输入一行,一个长度为
【输出数据】
从小到大输出所有可能的数,每个数一行,如果那个数不足
【样例输入】
【样例输出】
此题明显是用搜索做啊。
搜索每一位上的数字,时间复杂度为
我们来找一下有什么特点可以作为突破口。
我们发现,拿样例的
下面同理。
故我们在搜索的时候就可以剪枝掉了,大大缩减了时间复杂度。
var
t:string;
x:int64;
i,j,sum:longint;
a:array[0..5005] of string;
procedure dfs(k:longint;ans:int64);
var
c:string;
s,s1,_mod:int64;
i:longint;
begin
_mod:=1;
for i:=1 to k do _mod:=_mod*10;
if k=10 then
begin
str(ans,c);
while length(c)<9 do c:='0'+c;
inc(sum);
a[sum]:=c;
exit;
end;
for i:=0 to 9 do
begin
s:=0;s1:=0;
s:=ans+i*(_mod div 10);
s:=(s*s) mod _mod;
s1:=x mod _mod;
if s=s1 then dfs(k+1,ans+i*(_mod div 10));
end;
end;
begin
assign(input,'b.in');reset(input);
assign(output,'b.out');rewrite(output);
readln(x);
dfs(1,0);
for i:=1 to sum-1 do
for j:=i+1 to sum do
if a[i]>a[j] then
begin
t:=a[i];a[i]:=a[j];a[j]:=t;
end;
for i:=1 to sum do writeln(a[i]);
close(input);
close(output);
end.
【题目描述】
小
小
【输入数据】
第一行包括
第二行包括
第三行包括
【输出数据】
输出一行一个整数,表示最小切割代价。
【样例输入】
【样例输出】
【数据范围】
对于
对于
原题啊。。。
戳我,矩形分割
贪心,每一次取当前切割行或列最大的,因为你切下去一刀,就会相对应的另外一条就要多切一次,为了小,多切一次只能用在小的上面,代价才花的少。
这里我举了一个例子:
应该可以理解的吧。。
var
n,m,i,j,max1,max2,ans,sum:longint;
a:array[1..2,0..1005] of longint;
x,y:array[0..1005] of boolean;
begin
assign(input,'c.in');reset(input);
assign(output,'c.out');rewrite(output);
readln(n,m);
for i:=1 to n-1 do read(a[1,i]);
readln;
for i:=1 to m-1 do read(a[2,i]);
x[n+1]:=true;y[m+1]:=true;
ans:=1;
while ans<n*m do
begin
max1:=1;max2:=1;
for i:=1 to n-1 do
if a[max1,max2]<a[1,i] then
begin
max1:=1;
max2:=i;
end;
for i:=1 to m-1 do
if a[max1,max2]<a[2,i] then
begin
max1:=2;
max2:=i;
end;
if max1=1 then
begin
x[max2+1]:=true;
for i:=2 to m+1 do
if y[i]=true then
begin
inc(ans);
sum:=sum+a[max1,max2];
end;
end
else begin
y[max2+1]:=true;
for i:=2 to n+1 do
if x[i]=true then
begin
inc(ans);
sum:=sum+a[max1,max2];
end;
end;
a[max1,max2]:=-maxlongint;
end;
writeln(sum);
close(input);
close(output);
end.