JZOJ2017.08.15 C组

59 篇文章 0 订阅

T1

题目描述

我好菜啊!

思路:

较复杂的模拟。
详见代码。

代码:

var n,m,i,p,ans,j,l,r,c:longint;
    a,b,t:array[0..10110] of char;
begin
  assign(input,'eat.in');
  assign(output,'eat.out');
  reset(input);
  rewrite(output);
  readln(n);
  for i:=1 to n do begin read(a[i]); t[i]:=a[i]; end;  readln;
  for i:=1 to n do read(b[i]); readln;
  readln(m);
  for i:=1 to m do
  begin
    readln(l,r,c);
    c:=c mod(r-l+1);
    for j:=l to r do
    begin
      p:=(j+c-l+1)mod(r-l+1);
      if p=0 then p:=r-l+1;
      a[l+p-1]:=t[j];
    end;
    t:=a;
  end;
  for i:=1 to n do if b[i]=a[i] then inc(ans);
  write(ans);
  close(input);
  close(output);
end.

T2

题目描述

哈哈哈哈

思路:

用链表统计高度,从高到低枚举高度。

代码:

var n,i,x,y,j:longint;
    s,v,t,max,ans,maxh,maxc:longint;
    a:array[0..501,0..100001]of integer;
    b,c:array[0..100001]of longint;
begin
  assign(input,'house.in');
  assign(output,'house.out');
  reset(input);
  rewrite(output);
  read(n);
  for i:=1 to n do
  begin
    read(x,y);
    inc(a[y,x]); inc(b[x]); inc(c[x],y);
    if x>maxh then maxh:=x;
    if y>maxc then maxc:=y;
    ans:=ans+y;
  end;
  for i:=1 to maxc do
    for j:=1 to maxh do
      a[i,j]:=a[i,j]+a[i,j-1];
  for i:=maxh downto 1 do
  begin
    s:=b[i]-1; v:=c[i]; t:=maxc;
    while (t>0) do
    begin
      if s>=a[t,i-1] then
      begin
        dec(s,a[t,i-1]);
        v:=v+a[t,i-1]*t;
      end else
      begin
        v:=v+s*t;
        break;
      end;
      dec(t);
    end;
    if v>max then max:=v;
  end;
  write(ans-max);
  close(input);
  close(output);
end.

T3

题目描述

这里写图片描述

思路:

二分时间。
如果使用除草机的时间>mid 则不合法。

代码:

var a:array[-10..100011] of longint;
    n,m,i:longint;
    f:boolean;
procedure qsort(l,r:longint);
var i,j,mid:longint;
begin
  if l>=r then exit;
  i:=l; j:=r; mid:=a[(i+j) div 2];
  repeat
    while a[i]<mid do inc(i);
    while a[j]>mid do dec(j);
    if i<=j then
    begin
      a[0]:=a[i]; a[i]:=a[j]; a[j]:=a[0];
      //b[0]:=b[i]; b[i]:=b[j]; b[j]:=b[0];
      inc(i); dec(j);
    end;
  until i>=j;
  qsort(l,j);
  qsort(i,r);
end;
function find(l,r:longint):longint;
var mid,i,t:longint;
    //f:boolean;
begin
  if l>r then exit(l);
  mid:=(l+r) div 2;
  f:=true; t:=0;
  for i:=1 to n do
    if a[i]>mid then
    begin
      t:=t+(a[i]-mid) div m;
      if a[i] mod m>0 then inc(t);
      if t>mid then begin f:=false; break; end;
    end;
  if f then exit(find(l,mid-1)) else exit(find(mid+1,r));
end;
begin
  assign(input,'foreat.in');
  assign(output,'foreat.out');
  reset(input);
  rewrite(output);
  read(n,m);
  for i:=1 to n do read(a[i]);
  qsort(1,n);
  write(find(0,a[n]));
  close(input);
  close(output);
end.

T4

题目描述

这里写图片描述

思路:

其实我们只用枚举三个物品就行了,另一个自然而然得出。
var a:array[0..40000]of longint;
    b,d:array[0..15000]of int64;
    c:array[0..15000,1..4]of int64;
    i,j,n,m,t:longint;
begin
  assign(input,'magic.in');
  assign(output,'magic.out');
  reset(input);
  rewrite(output);
  read(n,m);
  for t:=1 to m do begin read(a[t]); inc(b[a[t]]); end;
  for t:=1 to (n-1) div 9 do
  begin
    fillchar(d,sizeof(d),0);
    for j:=n-t downto 8*t+1 do d[j]:=d[j+1]+b[j]*b[j+t];
    for j:=1 to n-9*t-1 do
    begin
      c[j,1]:=c[j,1]+b[j+2*t]*d[j+8*t+1];
      c[j+2*t,2]:=c[j+2*t,2]+b[j]*d[j+8*t+1];
    end;
    fillchar(d,sizeof(d),0);
    for j:=1 to n-9*t-1 do d[j]:=d[j-1]+b[j]*b[j+2*t];
    for j:=n-t downto 8*t+1 do
    begin
      c[j,3]:=c[j,3]+b[j+t]*d[j-8*t-1];
      c[j+t,4]:=c[j+t,4]+b[j]*d[j-8*t-1];
    end;
  end;
  for i:=1 to m do
    writeln(c[a[i],1],' ',c[a[i],2],' ',c[a[i],3],' ',c[a[i],4]);
  close(input);
  close(output);
end.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值