USACO Section 1.1 题解

 为了备战2011NOIp,我决定把USACO重新刷过,练代码感觉,顺便回顾以前学的算法。

我觉得USACO的题十分好十分强大十分给力,每做一次感觉都不同,比赛前刷刷USACO是最好的选择。

我最支持USACO这种进阶模式,像我刷RQNOJ时,毫无目的的刷题,刷到哪算哪,不会的跳过,搞的我一点激情都没...

记得以前刷USACO时,十分兴奋,基本没都久,第一章就刷完了,貌似之前快刷到第4章了,貌似被卡住了,之后就很久没做了

虽然,现在刷USACO没以前那么积极了,刷玩一题就想放松下玩玩,不过这样也好,反正是为了准备比赛,慢慢来嘛...其实有些题做过再做还是有提高的(说不定你曾看过题解,现在自己想出来了,这不是很大的提高吗?我自己貌似之前也看过题解吧....+.+)

 

--------------------------------------------------------------------------------------美丽的分界线-----------------------------------------------------------------------------------------

这一节主要考查代码能力,不详细说了....

 

 

USACO 1.1.1     Your Ride Is Here 你要乘坐的飞碟在这里

 

program ride(input,output);
const
  a:array['A'..'Z'] of integer=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26);
var
  m1,m2,i:longint;
  s1,s2:string;
procedure init;
 begin
   assign(input,'ride.in');
   assign(output,'ride.out');
   reset(input);
   rewrite(output);
 end;
procedure outit;
 begin
   close(input);
   close(output);
 end;
begin
  init;
  readln(s1);readln(s2);
  m1:=1;m2:=1;
  for i:=1 to length(s1) do
   begin
     m1:=m1*a[s1[i]];
     if m1>47 then m1:=m1 mod 47;
   end;
  for i:=1 to length(s2) do
   begin
     m2:=m2*a[s2[i]];
     if m2>47 then m2:=m2 mod 47;
   end;
  m1:=m1 mod 47; m2:=m2 mod 47;
  if m1=m2 then writeln('GO')
           else writeln('STAY');
  outit;
end.


 

 

USACO 1.1.2 Greedy Gift Givers 贪婪的礼物送礼者

 

program gift1(input,output);
type
   data=record
       money:longint;
       name:string;
     end;
var
  n,i,j,x,y,k:longint;
  s:string;
  a:array[1..100] of data;
procedure init;
 begin
   assign(input,'gift1.in');
   assign(output,'gift1.out');
   reset(input);
   rewrite(output);
 end;
procedure outit;
 begin
   close(input);
   close(output);
 end;
begin
  init;
  readln(n);
  for i:=1 to n do readln(a[i].name);
  for i:=1 to n do
    begin
      readln(s);
      readln(x,y);
      if (x<>0)and(y<>0) then
        begin
          k:=1;
          while s<>a[k].name do inc(k);
          dec(a[k].money,x-x mod y);
        end;
          for j:=1 to y do
            begin
              readln(s);
              if x<>0 then
               begin
                k:=1;
                while s<>a[k].name do inc(k);
                inc(a[k].money,x div y);
               end;
            end;
    end;
  for i:=1 to n do writeln(a[i].name,' ',a[i].money);
  outit;
end.


 

 

USACO 1.1.3 Friday the Thirteenth 黑色星期五

 

program friday(input,output);
const
 month:array[0..1,1..12] of integer=((3,0,3,2,3,2,3,3,2,3,2,3),(3,1,3,2,3,2,3,3,2,3,2,3));    //月份都减去28了,0是平年,1是闰年
var
 a:array[0..6] of integer;
 i,k,j,h,n:longint;
procedure init;
begin
 assign(input,'friday.in');
 assign(output,'friday.out');
 reset(input);
 rewrite(output);
end;
procedure outit;
begin
 close(input);
 close(output);
end;
begin
 init;
 readln(n);h:=6;
 for i:=1900 to 1900+n-1 do
  begin
   if (i mod 400=0) or ((i mod 100<>0) and (i mod 4=0)) then k:=1 else k:=0;
   for j:=1 to 12 do
    begin
     inc(a[h]);
     h:=(h+month[k,j]) mod 7;
    end;
  end;
 writeln(a[6],' ',a[0],' ',a[1],' ',a[2],' ',a[3],' ',a[4],' ',a[5]);
 outit;
end.


 

 

USACO 1.1.4Broken Necklace破碎的项链

 

program beads(input,output);
var
  n,i,max,ans,k:longint;
  ch:char;
  s:ansistring;               //在pascal中string只有255个字符,要用ansistring,其他语言不知道到要不要注意
procedure init;
begin
 assign(input,'beads.in');
 assign(output,'beads.out');
 reset(input);
 rewrite(output);
end;
procedure outit;
begin
 close(input);
 close(output);
end;
begin
  init;
  readln(n);
  readln(s);
  s:=s+s+s;
  for i:=n+1 to n+n do
    begin
      ans:=0;
      k:=i-1;                                       //left
      ch:='w';
      while (ch='w')or(ch=s[k])or(s[k]='w') do
        begin
          inc(ans);
          if s[k]<>'w' then ch:=s[k];
          dec(k);
        end;
      k:=i;                                         //right
      ch:='w';
      while (ch='w')or(ch=s[k])or(s[k]='w') do
        begin
          inc(ans);
          if s[k]<>'w' then ch:=s[k];
          inc(k);
        end;
      if ans>max then max:=ans;
      if ans>n then begin max:=n; break;end;
    end;
  writeln(max);
  outit;
end.


 

你可能感兴趣的:(USACO)