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

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. .NET开源项目介绍及资源推荐:数据持久层

    在.NET平台下,关于数据持久层框架非常多,本文主要对如下几种做简要的介绍并推荐一些学习的资源: 1.NHibernate 2.NBear 3.Castle ActiveRecord 4.iBATIS ...

  2. Cookie 获取

    二级域名可以获取一级域名的Cookie值 二级域名下删除顶级域名下的Cookie,需要添加顶级域名的Cookie作用域 /// <summary> /// 根据cookie名称删除 /// ...

  3. .Xresources 配置文件

    安装rxvt-unicode-256color,如果不是这个版本的话VIM配色会显示不正常. ~/.Xresources配置文件如下 !urxvt color scheme: URxvt*backgr ...

  4. 邻结矩阵的建立和 BFS,DFS;;

    邻结矩阵比较简单,, 它的BFS,DFS, 两种遍历也比较简单,一个用队列, 一个用数组即可!!!但是邻接矩阵极其浪费空间,尤其是当它是一个稀疏矩阵的时候!!!-------------------- ...

  5. word小技巧

    如何将英文和数字替换为times new romans 1,点击替换(ctrl+H) .2,在查找内容中输入”([A-Z0-9])“(不包括引号,但包括小括号),这是替换所有大写字母和数字,如果还想替 ...

  6. 模仿开发H5游戏,看你有多色

    开发记录 前言 之前跟着慕课网学习开发H5小游戏开心鱼,勾起我的兴趣. 在写代码的过程中,不怎么会遇到问题.虽然代码是亲手敲出来的,但是由于并没有对游戏的整体思路,所以并不知道开发与优化的过程. 为了 ...

  7. 输入一个链表,输出该链表中倒数第k个结点。

    // test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  8. 让站长在SEO时更得心应手的六个细节

    分析一下SEO的心得,希望能对很多做网站优化和做网站推广的站长有帮助,现在做SEO的人越来网站推广越多,即使很多人在做,但不知道自己能否成功,自己的优化是否会见效,所以在这里还是来分享一下咱们在SEO ...

  9. 【BZOJ】【3143】【HNOI2013】游走

    数学期望/高斯消元/贪心 啊……用贪心的思路明显是要把经过次数期望越大的边的权值定的越小,那么接下来的任务就是求每条边的期望经过次数. 拆边为点?nonono,连接x,y两点的边的期望经过次数明显是 ...

  10. Unity3D研究院之IOS全自动编辑framework、plist、oc代码

    Unity打IOS时会先生成一个Xcode工程,如果你需要增加一些第三方的framework那么需要手动一条一条的添加,这太烦了..而且可能你还需要修改Plist文件,甚至还可能要修改unity自动生 ...