百度NOIP吧编程挑战赛 标程

文章目录

第一题

program crack;
type
  node=record
    data:string;
    cost:longint;
  end;
  arr=array[1..50000] of node;
var  a:arr;
     n,m:longint;
     table:array[97..122] of integer=(4,2,5,6,1,4,5,6,7,2,3,4,8,9,3,1,2,6,8,9,2,6,3,2,5,7);
procedure print;
var i:longint;
begin
  for i:=1 to m do
   writeln(a[i].data,' ',a[i].cost);
end;

function max(s1,s2:string):boolean;
var i:longint;
begin
  if length(s1)>length(s2) then exit(true) else
   if length(s1)ord(s2[i]) then exit(true) else
      if ord(s1[i]) 

procedure qsort(l,r:longint);
var  i,j,k:longint;
     ks:string;
     temp:node;
begin
  i:=l;  j:=r;  k:=a[random(r-l)+l].cost;  ks:=a[random(r-l)+l].data;
  repeat
    while (ka[j].cost) or ((k=a[j].cost) and (max(ks,a[j].data))) do dec(j);
    if i<=j then
     begin
       temp.cost:=a[i].cost;       a[i].cost:=a[j].cost;       a[j].cost:=temp.cost;
       temp.data:=a[i].data;       a[i].data:=a[j].data;       a[j].data:=temp.data;
       inc(i);       dec(j);
     end;
  until i>j;
  if il then qsort(l,j);
end;
function cost(s:string):longint;
var  i:longint;
begin
  cost:=0;
  for i:=1 to length(s) do  inc(cost,table[ord(s[i])]);
  exit(cost);
end;
procedure init;
var  i:longint;
begin
  readln(n,m);
  for i:=1 to n do
    begin
      readln(a[i].data);
      a[i].cost:=cost(a[i].data);
    end;
end;
begin
  assign(input,'crack.in');  reset(input);
  assign(output,'crack.out');  rewrite(output);
  init;
  qsort(1,n);
  print;
  close(input);
  close(output);
end.

第二题

Program contact;
Const
  infile = 'contact.in';
  outfile = 'contact.out';
Var
  a : Array[1..1001, 1..1001] Of longint;
  p : Array[1..1001] Of Record
    x, y : Longint;
  End;
  s, back : Array[1..1001] Of Longint;
  ans, anss, min, i, j, k, n, m, x, y : Longint;
Begin
  Assign(input, infile);
  Reset(input);
  Readln(n);
  Inc(n);
  For i:=1 To n Do Begin
    For j:=1 To n Do Begin
      Read(a[i, j]);
    End;
    Readln;
  End;
  Readln(m);
  For i:=1 To m Do Begin
    Readln(x, y);
    a[x, y] := -1;
    a[y, x] := -1;
  End;
  For i:=1 To n Do s[i] := 1999999999;
  s[1] := 0;
  ans := 0;
  anss := 0;
  For i:=1 To n Do Begin
    min := 1999999999;
    For j:=1 To n Do If s[j] <> -2 Then Begin
      If s[j] < min Then Begin
        min := s[j];
        k := j;
      End;
    End;
    s[k] := -2;
    If min > -1 Then Begin
      ans := ans + min;
      anss := anss + 1;
      p[anss].x := back[k];
      p[anss].y := k;
    End;
    For j:=1 To n Do If s[j] > -2 Then Begin
      If a[k, j] < s[j] Then Begin
        s[j] := a[k, j];
        back[j] := k;
      End;
    End;
  End;
  Assign(output, outfile);
  Rewrite(output);
  Writeln(ans);
  For i:=2 To anss Do Writeln(p[i].x, ' ', p[i].y);
  Close(output);
End.             

第三题

var
  n,C,i,j:longint;
  x,w,b,t:array[0..10001]of longint;
  f:array[0..10001,0..400]of longint;
procedure qsort(s,e:longint);
var
  i,j,k,xx,bb:longint;
begin
  i:=s;
  j:=e;
  k:=(s+e) shr 1;
  xx:=x[k];
  x[k]:=x[s];
  bb:=b[k];
  b[k]:=b[s];
  while i=xx) do dec(j);
    if is then qsort(s,i-1);
  if j+1f[k,j] then
        f[k,j]:=f[i,j-1];
  end;
end;
begin
  assign(input,'charge.in');   reset(input);
  assign(output,'charge.out');   rewrite(output);
  readln(n,C);
  for i:=1 to n do begin
    readln(x[i],w[i]);
    b[i]:=i;
  end;
  qsort(1,n);
  t[0]:=1;
  for i:=1 to n do
    if t[x[i]]=0 then t[x[i]]:=i;
  t[n+1]:=n+1;
  for i:=n downto 1 do
    if t[i]=0 then t[i]:=t[i+1];
  fillchar(f,sizeof(f),0);
  f[0,1]:=40000000;
  dfs(0,C);
  j:=0;
  for i:=0 to C do
    if f[0,i]>j then j:=f[0,i];
  writeln(j);
  close(input);
  close(output);
end. 

第四题

program switch;
const num:array[0..15] of integer=(4,2,0,4,0,7,7,2,2,7,7,0,4,0,2,4);
      s:array[0..15,1..7] of integer=((0,1,4,5,0,0,0),(1,2,0,0,0,0,0),(0,0,0,0,0,0,0),(2,3,6,7,0,0,0),
                                      (0,0,0,0,0,0,0),(1,4,5,6,7,9,13),(2,4,5,6,7,10,14),(7,11,0,0,0,0,0),
                                      (4,8,0,0,0,0,0),(1,5,8,9,10,11,13),(2,6,8,9,10,11,14),(0,0,0,0,0,0,0),
                                      (8,9,12,13,0,0,0),(0,0,0,0,0,0,0),(13,14,0,0,0,0,0),(10,11,14,15,0,0,0));
      ni:array[0..15] of boolean=(false,false,true,false,true,false,false,false,
                                  false,false,false,true,false,true,false,false);
      finish:array[0..15] of boolean=(false,false,false,false,false,true,true,false,
                                      false,true,true,false,false,false,false,false);
      six:array[0..15] of string[1]=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
      two:array[0..3] of integer=(8,4,2,1);
var ans:array[0..15,0..15,0..15,0..15] of string[16];
    a,zqm:array[0..15] of boolean;
    p,p1,i,j,k,n:integer;
    t,b4:array[1..4] of integer;
    st:string[16];
    ch:string;
    i0,i1,i3,i5,i6,i7,i8,i9,i10,i12,i14,i15:boolean;
    sum:longint;
begin
  assign(input,'switch.in');
  assign(output,'switch.out');
  reset(input);
  rewrite(output);
  fillchar(a,sizeof(a),0);
  for i0:=false to true do
  for i1:=false to true do
  for i3:=false to true do
  for i5:=false to true do
  for i6:=false to true do
  for i7:=false to true do
  for i8:=false to true do
  for i9:=false to true do
  for i10:=false to true do
  for i12:=false to true do
  for i14:=false to true do
  for i15:=false to true do
  begin
   a[0]:=i0;  a[1]:=i1;  a[3]:=i3;  a[5]:=i5;  a[6]:=i6;  a[7]:=i7;  a[8]:=i8;
   a[9]:=i9;  a[10]:=i10;  a[12]:=i12;  a[14]:=i14;  a[15]:=i15;
  zqm:=finish;
  for p:=0 to 15 do
    if not ni[p] and a[p] then
      for k:=1 to num[p] do zqm[s[p,k]]:=not zqm[s[p,k]];
  fillchar(t,sizeof(t),0);
  for p:=1 to 4 do
    for p1:=0 to 3 do
      if zqm[(p-1)*4+p1] then t[p]:=t[p]+two[p1];
  st:='';
  for p:=0 to 15 do
    if a[p] then st:=st+six[p];
  ans[t[1],t[2],t[3],t[4]]:=st;
  end;
  readln(n);
  fillchar(b4,sizeof(b4),0);
  for j:=1 to n do begin
   readln(ch);
    for i:=1 to 4 do begin
     if ch[i] in ['A'..'F'] then b4[i]:=ord(ch[i])-55 else b4[i]:=ord(ch[i])-48;
    end;
    writeln(ans[b4[1],b4[2],b4[3],b4[4]]);
  end;
  close(input);
  close(output);
end.

题外话:我帮你整理了包括 AI 写作、绘画、视频(自媒体制作)零门槛 AI 课程 + 国内可直接顺畅使用的软件。想让自己快速用上 AI 工具来降本增效,辅助工作和生活?限时报名

当前页阅读量为: