usaco 2.1 hamming 2008.6.10

usaco 2.1 hamming 2008.6.10

{

ID:

PROG: hamming

LANG: PASCAL

}

program p_hamming;

const g:array[1..8]oflongint=(1,2,4,8,16,32,64,128);

 fin='hamming.in';fout='hamming.out';

var

   f1,f2:text;

  x:array[1..8,1..255]of longint;

  y:array[1..8]of longint;

  a:array[1..65]of longint;

  la,i,n,b,d:longint;

procedure qsort(i,j:longint);

var

l,r,x,y:longint;

begin

l:=i;r:=j;

x:=a[(l+r) div 2];

repeat

while a[l]<x do inc(l);

while a[r]>x do dec(r);

 ifl<=r then

  begin

  y:=a[l];

  a[l]:=a[r];

  a[r]:=y;

  inc(l);

  dec(r);

  end;

until l>r;

if r>i then qsort(i,r);

if l<j then qsort(l,j);

end;

 

function too(r:longint):longint;

var i:longint;

begin

   too:=0;

    for i:=8 downto 1 do

    if r>=g[i] then

      begin inc(too);dec(r,g[i]);end;

end;

function deal(t:longint):boolean;

var k,p,w:longint;

begin

  fork:=1 to la do

  begin

   p:=t xor a[k];w:=too(p);

   if w<d then exit(false);

  end;

 exit(true);

end;

procedure doit;

var i,j:longint;u:boolean;

begin la:=1;i:=0;a[1]:=0;

repeat

    inc(i);u:=deal(i);

    if u then begin inc(la);a[la]:=i;end;

until (la=n);

end;

{----------------------------------}

begin

 assign(f1,fin);reset(f1);

 assign(f2,fout);rewrite(f2);

  read(f1,n,b,d);

 doit;

 qsort(1,n);

  fori:=1 to n-1 do if i mod 10=0 then writeln(f2,a[i]) else write(f2,a[i],' ');

 writeln(f2,a[n]);

 close(f1);

 close(f2);

 end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值