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

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

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

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

 type node=array[..] of int64;

 var a,b,c,d:node;
j,i,n,m,t1,t2:longint; procedure qsort(var a:node; n:longint);
procedure sort(l,r: longint);
var i,j:longint;
x,y:int64;
begin
i:=l;
j:=r;
x:=a[(l+r) div ];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; begin
sort(,n);
end; procedure pre;
begin
c:=a;
d:=b;
n:=t1; m:=t2;
end; function work:boolean;
var turn:boolean;
begin
turn:=true;
while true do
begin
if n= then exit(false);
if m= then exit(true);
if turn then
begin
if (c[n]>d[m]) and (m>) then
begin
dec(m);
d[m]:=d[m]+d[m+];
d[m+]:=;
end
else if c[n]<d[m] then
begin
c[n]:=;
dec(n)
end
else exit(true);
end
else begin
if (c[n]>d[m]) then
begin
d[m]:=;
dec(m);
end
else if (c[n]<d[m]) and (n>) then
begin
dec(n);
c[n]:=c[n]+c[n+];
c[n+]:=;
end
else exit(false);
end;
turn:=not turn;
end;
end; function check:boolean;
var fl:boolean;
begin
check:=false;
if a[t1]>b[t2] then
begin
pre;
d[m]:=;
dec(m);
fl:=work;
if fl then exit(true);
end;
if t1> then
begin
pre;
dec(n);
c[n]:=c[n]+c[n+];
c[n+]:=;
fl:=work;
if fl then exit(true);
end;
end; begin
while not eof do
begin
inc(j);
readln(t1,t2);
for i:= to t1 do
read(a[i]);
for i:= to t2 do
read(b[i]);
readln;
qsort(a,t1);
qsort(b,t2);
write('Case ',j,': ');
if check then writeln('Takeover Incorporated')
else writeln('Buyout Limited');
end;
end.

bzoj3983的更多相关文章

随机推荐

  1. 【转】在RedHat上搭建自己Email服务器

    原文:http://6839976.blog.51cto.com/6829976/1323482 by LN__@linux 目前邮件服务器中,想要拥有自己的邮件服务器,单单使用senmail,pos ...

  2. mysql innodb 引擎

    innodb 引擎 一.概述 InnoDB 是一个用的比较广泛的存储引擎,因为它支持事物和外键,还有不错的效率;我们先看看官方教程怎么说; 我们先读一下, 对于上面的文档, 对一个InnoDB的表首先 ...

  3. jquery常用函数与方法汇总

    1.delay(duration,[queueName]) 设置一个延时来推迟执行队列中之后的项目. jQuery1.4新增.用于将队列中的函数延时执行.他既可以推迟动画队列的执行,也可以用于自定义队 ...

  4. PHP输出中文乱码的问题

    用echo输出的中文显示成乱码, 其实应该是各种服务器脚本都会遇到这个问题, 根本还是编码问题, 一般来说出于编码兼容考虑大多的页面都将页面字符集定义为utf-8 <meta http-equi ...

  5. spring @resource @ Autowired

    Spring中什么时候用@Resource,什么时候用@service 当你需要定义某个类为一个bean,则在这个类的类名前一行使用@Service("XXX"),就相当于讲这个类 ...

  6. Linq to Entity中连接两个数据库时要注意的问题

    Linq to Entity中连接两个数据库时要注意的问题 今天大学同学问了我一个问题,Linq to Entity中连接两个数据库时,报错“指定的 LINQ 表达式包含对与不同上下文关联的查询的引用 ...

  7. JavaSE GUI显示列表 JTable的刷新 重新加载新的数据

    JTable在显示所有数据之后,假如需要搜索某个名字,则会获取新的列表数据. 假设datas是JTable的数据,定义为: private Vector<Vector> datas = n ...

  8. JS操作Radio与Select

    //radio的chang事件,以及获取选中的radio的值 $("input[name=radioName]").on("change", function( ...

  9. BZOJ 3129 SDOI2013 方程

    如果没有限制,答案直接用隔板法C(m-1,n-1) 对于>=x的限制,我们直接在对应位置先放上x-1即可,即m=m-(x-1) 对于<=x的限制,由于限制很小我们可以利用容斥原理将它转化为 ...

  10. lintcode 中等题:A + B Problem A + B 问题

    题目: 中等 A + B 问题 给出两个整数a和b, 求他们的和, 但不能使用 + 等数学运算符. 如果 a=1 并且 b=2,返回3 注意 你不需要从输入流读入数据,只需要根据aplusb的两个参数 ...