zoukankan      html  css  js  c++  java
  • bzoj1034

    贪心

    尽可能让最强的赢,最弱的赢,都不行则最弱打最强

    感性的想,我肯定要尽可能的赢,而且赢的要对等

    实在不能赢就拿最小的拼,所谓的田忌赛马策略

    由于总分一定,己方最差即己方最好时对方的分数

     1 type list=array[0..100010] of longint;
     2 var a,b:list;
     3     n,i:longint;
     4 
     5 procedure qsort(var a:list);
     6   procedure sort(l,r: longint);
     7     var i,j,x,y: longint;
     8     begin
     9       i:=l;
    10       j:=r;
    11       x:=a[(l+r) div 2];
    12       repeat
    13         while a[i]>x do inc(i);
    14         while x>a[j] do dec(j);
    15         if not(i>j) then
    16         begin
    17           y:=a[i];
    18           a[i]:=a[j];
    19           a[j]:=y;
    20           inc(i);
    21           j:=j-1;
    22         end;
    23       until i>j;
    24       if l<j then sort(l,j);
    25       if i<r then sort(i,r);
    26     end;
    27 
    28   begin
    29     sort(1,n);
    30   end;
    31 
    32 function ans(a,b:list):longint;
    33   var h1,t1,h2,t2:longint;
    34   begin
    35     ans:=0;
    36     h1:=1;
    37     h2:=1;
    38     t1:=n;
    39     t2:=n;
    40     while (h1<=t1) do
    41     begin
    42       if a[h1]>b[h2] then
    43       begin
    44         inc(h1);
    45         inc(h2);
    46         ans:=ans+2;
    47       end
    48       else if a[t1]>b[t2] then
    49       begin
    50         dec(t1);
    51         dec(t2);
    52         ans:=ans+2;
    53       end
    54       else begin
    55         if a[t1]=b[h2] then inc(ans);
    56         dec(t1);
    57         inc(h2);
    58       end;
    59     end;
    60   end;
    61 
    62 begin
    63   readln(n);
    64   for i:=1 to n do
    65     readln(a[i]);
    66   qsort(a);
    67   for i:=1 to n do
    68     readln(b[i]);
    69   qsort(b);
    70   writeln(ans(a,b),' ',2*n-ans(b,a));
    71 end.
    View Code
  • 相关阅读:
    JavaScript学习总结(一)——ECMAScript、BOM、DOM(核心、浏览器对象模型与文档对象模型)
    IDEL——maven的搭建
    JDBC——Mysql 5.7绿色版配置安装过程
    JAVA的面向对象编程--------课堂笔记
    Javaweb第九章、jsp引入JSTL
    jsp引入JSTL后实现jsp的解耦
    servret的引入
    网页设计学习笔记小结
    jdk和Tomcat环境变量设置
    SLZ-VMware虚拟机_ORACLE安装监听器
  • 原文地址:https://www.cnblogs.com/phile/p/4473167.html
Copyright © 2011-2022 走看看