zoukankan      html  css  js  c++  java
  • bzoj3983

    显然我们得到这样几个结论

    1.每次攻击对方一定是攻击最大的

    2.自己合并也是合并最大和次大的

    我们只要穷举下一开始是攻击还是合并,之后就是能攻击先攻击否则就合并

      1 type node=array[0..100010] of int64;
      2 
      3 var a,b,c,d:node;
      4     j,i,n,m,t1,t2:longint;
      5 
      6 procedure qsort(var a:node; n:longint);
      7   procedure sort(l,r: longint);
      8     var i,j:longint;
      9         x,y:int64;
     10     begin
     11       i:=l;
     12       j:=r;
     13       x:=a[(l+r) div 2];
     14       repeat
     15         while a[i]<x do inc(i);
     16         while x<a[j] do dec(j);
     17         if not(i>j) then
     18         begin
     19           y:=a[i];
     20           a[i]:=a[j];
     21           a[j]:=y;
     22           inc(i);
     23           j:=j-1;
     24         end;
     25       until i>j;
     26       if l<j then sort(l,j);
     27       if i<r then sort(i,r);
     28     end;
     29 
     30   begin
     31     sort(1,n);
     32   end;
     33 
     34 procedure pre;
     35   begin
     36     c:=a;
     37     d:=b;
     38     n:=t1; m:=t2;
     39   end;
     40 
     41 function work:boolean;
     42   var turn:boolean;
     43   begin
     44     turn:=true;
     45     while true do
     46     begin
     47       if n=0 then exit(false);
     48       if m=0 then exit(true);
     49       if turn then
     50       begin
     51         if (c[n]>d[m]) and (m>1) then
     52         begin
     53           dec(m);
     54           d[m]:=d[m]+d[m+1];
     55           d[m+1]:=0;
     56         end
     57         else if c[n]<d[m] then
     58         begin
     59           c[n]:=0;
     60           dec(n)
     61         end
     62         else exit(true);
     63       end
     64       else begin
     65         if (c[n]>d[m]) then
     66         begin
     67           d[m]:=0;
     68           dec(m);
     69         end
     70         else if (c[n]<d[m]) and (n>1) then
     71         begin
     72           dec(n);
     73           c[n]:=c[n]+c[n+1];
     74           c[n+1]:=0;
     75         end
     76         else exit(false);
     77       end;
     78       turn:=not turn;
     79     end;
     80   end;
     81 
     82 function check:boolean;
     83   var fl:boolean;
     84   begin
     85     check:=false;
     86     if a[t1]>b[t2] then
     87     begin
     88       pre;
     89       d[m]:=0;
     90       dec(m);
     91       fl:=work;
     92       if fl then exit(true);
     93     end;
     94     if t1>1 then
     95     begin
     96       pre;
     97       dec(n);
     98       c[n]:=c[n]+c[n+1];
     99       c[n+1]:=0;
    100       fl:=work;
    101       if fl then exit(true);
    102     end;
    103   end;
    104 
    105 begin
    106   while not eof do
    107   begin
    108     inc(j);
    109     readln(t1,t2);
    110     for i:=1 to t1 do
    111       read(a[i]);
    112     for i:=1 to t2 do
    113       read(b[i]);
    114     readln;
    115     qsort(a,t1);
    116     qsort(b,t2);
    117     write('Case ',j,': ');
    118     if check then writeln('Takeover Incorporated')
    119     else writeln('Buyout Limited');
    120   end;
    121 end.
    View Code
  • 相关阅读:
    HDU 5744
    HDU 5815
    POJ 1269
    HDU 5742
    HDU 4609
    fzu 1150 Farmer Bill's Problem
    fzu 1002 HangOver
    fzu 1001 Duplicate Pair
    fzu 1150 Farmer Bill's Problem
    fzu 1182 Argus 优先队列
  • 原文地址:https://www.cnblogs.com/phile/p/4590662.html
Copyright © 2011-2022 走看看