CF546C.Soldier and Cards

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.

The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.

You have to calculate how many fights will happen and who will win the game, or state that game won't end.

两个无聊的士兵正在玩纸牌对战游戏。他们的纸牌副牌恰好包含 nn 张牌,编号从 11 到 nn,所有牌面值互不相同。他们以某种方式将牌分发给彼此(双方所持牌数可能不同),然后开始进行一种类似“战争”(War)的纸牌游戏。

游戏规则如下:每一轮进行一次“战斗”。双方各自从自己牌堆的顶部取出一张牌并置于桌上。牌面值较大的一方赢得本轮战斗,并将桌上的两张牌按顺序加入自己牌堆的底部:具体而言,他先将对手的牌放入自己牌堆底部,再将自己的牌放入自己牌堆底部。若某轮结束后,某位玩家的牌堆变为空,则该玩家输掉游戏,另一位玩家获胜。

你需要计算总共会发生多少轮战斗、最终谁将获胜,或者判断该游戏将永不结束。

输入格式

First line contains a single integer n (2 ≤ n ≤ 10), the number of cards.

Second line contains integer _k_1 (1 ≤ _k_1 ≤ n - 1), the number of the first soldier's cards. Then follow _k_1 integers that are the values on the first soldier's cards, from top to bottom of his stack.

Third line contains integer _k_2 (_k_1 + _k_2 = n), the number of the second soldier's cards. Then follow _k_2 integers that are the values on the second soldier's cards, from top to bottom of his stack.

All card values are different.

第一行包含一个整数 nn(2≤n≤102 \leq n \leq 10),表示卡片总数。

第二行包含整数 k1k_1(1≤k1≤n−11 \leq k_1 \leq n - 1),表示第一位士兵所持卡片的数量;随后是 k1k_1 个整数,表示第一位士兵手中卡片的数值,按其牌堆从上到下的顺序给出。

第三行包含整数 k2k_2(满足 k1+k2=nk_1 + k_2 = n),表示第二位士兵所持卡片的数量;随后是 k2k_2 个整数,表示第二位士兵手中卡片的数值,按其牌堆从上到下的顺序给出。

所有卡片的数值互不相同。

输出格式

If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.

If the game won't end and will continue forever output  - 1.

如果有人在该游戏中获胜,请输出两个整数,其中第一个整数表示游戏结束前的战斗次数,第二个整数为 1 或 2,表示获胜的玩家编号。

如果游戏无法结束并将永远持续下去,则输出 −1-1。

输入输出样例

  • 输入#1

    4
    2 1 3
    2 4 2

    输出#1

    6 2
  • 输入#2

    3
    1 2
    2 1 3

    输出#2

    -1

说明/提示

First sample:

Second sample:

第一个样例:

第二个样例:

输入解题思路,AI测评打分。不知道怎么写?

首页