zoukankan      html  css  js  c++  java
  • 最小最大和 (Standard IO)

    题意/Description:

           Alice和Bob在玩一个游戏,每一轮Bob都会给Alice两个整数A和B(1<=A,B<=100),Alice每一轮必须把目前所有的A序列和B序列中的数一一配对,每个数必须用且只使用一次,要求最大和最小。

     

    读入/Input

           第一行一个整数N(1<=N<=100000),表示比赛的轮数。
      接下来N行每行包含两个整数A和B(1<=A,B<=100),表示Bob这一轮给的两个数。

     

    输出/Output

           输出N行,每行输出最小的最大和。

     

    题解/solution

           看到n很大,就崩溃了。不过a和b只有100,自信的打了一个桶排。说到这,后面就暴力吧。

           点赞......

     

    代码/Code

    var
      n,max:longint;
      a,b,c,d:array [-100..201] of longint;
    procedure init;
    var
      x,y,k,i,j:longint;
    begin
      readln(n);
      for k:=1 to n do
        begin
          readln(x,y);
          inc(c[x]); inc(d[y]);
          a:=c; b:=d;
          i:=1; j:=100; max:=0;
          while 1=1 do
            begin
              while (a[i]=0) and (i<110) do inc(i);
              while (b[j]=0) and (j>-10) do dec(j);
              if (i>100) and (j<0) then break;
              if a[i]>b[j] then
                begin
                  a[i]:=a[i]-b[j];
                  b[j]:=0;
                end else
                begin
                  b[j]:=b[j]-a[i];
                  a[i]:=0;
                end;
              if i+j>max then max:=i+j;
            end;
          writeln(max);
        end;
    end;
    
    begin
      init;
    end.



  • 相关阅读:
    Heroku
    Git基本命令(转)
    github之从零开发
    物理层、、。。。
    BeautifulSoup, 的使用
    路径设置
    http协议
    Python 的os模块与sys模块
    python 操作MySQL数据库
    多进程记要
  • 原文地址:https://www.cnblogs.com/zyx-crying/p/9319644.html
Copyright © 2011-2022 走看看