• poj 2503 快排+二分


    var x,y:array[0..110000] of string;
        i,n,l,r,mid:longint;
        s:string;
    procedure qsort(h,l:longint);
     var i,j:longint;
         temp,m:string;
     begin
     i:=h;j:=l;m:=x[(i+h)>>1];
     repeat
      while x[i]<m do inc(i);
      while x[j]>m do dec(j);
      if i<=j then
       begin
        temp:=x[i];x[i]:=x[j];x[j]:=temp;
        temp:=y[i];y[i]:=y[j];y[j]:=temp;
        inc(i);dec(j);
       end;
     until i>j;
     if i<l then qsort(i,l);
     if j>h then qsort(h,j);
     end;
    procedure init;
     begin
     n:=0;
     while true do
      begin
      readln(s);if s='' then break;
      inc(n);
      y[n]:=copy(s,1,pos(' ',s)-1);
      delete(s,1,pos(' ',s));
      x[n]:=s;
      end;
     qsort(1,n);
     end;
    procedure main;
     begin
     while true do
      begin
      readln(s);if s='' then break;
      l:=1;r:=n;
      while l<r do
       begin
       mid:=(l+r)>>1;
       if s<x[mid] then r:=mid
       else if s>x[mid] then l:=mid+1
       else begin l:=mid;r:=mid;end;
       end;
      if x[l]=s then writeln(y[l]) else writeln('eh');
      end;
     end;
    begin
     init;
     main;
    end.    
    View Code

    水一道……体验了一把1A的感觉……

    还要说的是,这道题的字符串达到了100000,但还是能够直接排序处理,那是因为它的字符串太短了……

    var x,y:array[0..110000] of string;
        i,n,l,r,mid:longint;
        s:string;
    procedure qsort(h,l:longint);
     var i,j:longint;
         temp,m:string;
     begin
     i:=h;j:=l;m:=x[(i+h)>>1];
     repeat
      while x[i]<m do inc(i);
      while x[j]>m do dec(j);
      if i<=j then
       begin
        temp:=x[i];x[i]:=x[j];x[j]:=temp;
        temp:=y[i];y[i]:=y[j];y[j]:=temp;
        inc(i);dec(j);
       end;
     until i>j;
     if i<l then qsort(i,l);
     if j>h then qsort(h,j);
     end;
    procedure init;
     begin
     n:=0;
     while true do
      begin
      readln(s);if s='' then break;
      inc(n);
      y[n]:=copy(s,1,pos(' ',s)-1);
      delete(s,1,pos(' ',s));
      x[n]:=s;
      end;
     qsort(1,n);
     end;
    procedure main;
     begin
     while true do
      begin
      readln(s);if s='' then break;
      l:=1;r:=n;
      while l<r do
       begin
       mid:=(l+r)>>1;
       if s<x[mid] then r:=mid
       else if s>x[mid] then l:=mid+1
       else begin l:=mid;r:=mid;end;
       end;
      if x[l]=s then writeln(y[l]) else writeln('eh');
      end;
     end;
    begin
     init;
     main;
    end.    
  • 相关阅读:
    session 和 aplication 相关总结
    asp.net网站发布时碰到的一些问题
    考前防脑瘫防挂分预防针
    【游记】NOIP2021 白给记
    SELECT list is not in GROUP BY clause and contains nonaggregated
    StringUtils.isEmpty()
    gitLab生成SSH私钥后上传代码及获取代码
    tomcat配置https请求访问
    Mybatis:映射文件概述 & 增删改查
    Mybatis:核心文件概述
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3771818.html
Copyright © 2020-2023  润新知