【CodeForces - 546C 】Soldier and Cards (模拟)

题干:

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.

Input

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

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

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

All card values are different.

Output

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.

Examples

Input

4
2 1 3
2 4 2

Output

6 2

Input

3
1 2
2 1 3

Output

-1

Note

First sample:

Second sample:

 

题目大意:

    两个人玩纸牌游戏,每一轮游戏每个人都把自己的第一个牌拿出来比较大小,大的一方先将对面的这个牌放在自己牌的最后,再把自己的牌放在最后,直到一个人没有了纸牌就算那个人输,问一共会进行多少次游戏,以及赢的人的编号。如果决不出胜负那就输出-1

解题报告:

   模拟就行了。猜他最多不超过1e7次、、其实这题的上界是4e7次,因为你想啊,最多的排列可能是n!种,然后分到两个人手中,可能每个人手中的牌有(0,n)(1,n-1)...(n,0)共(n+1)中可能性,所以一共的局面有(n+1)!种情况,算一下最多4e7左右。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#include<ctime>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 2e5 + 5;
int n,k1,k2;
deque<int> a,b;
int main()
{cin>>n;cin>>k1;for(int x,i = 1; i<=k1; i++) {scanf("%d",&x);a.pb(x);}cin>>k2;for(int x,i = 1; i<=k2; i++) {scanf("%d",&x);b.pb(x);}if(k1 == 0) return 0 * printf("0 2\n");if(k2 == 0) return 0 * printf("0 1\n");int i;int flag = 0;for(i = 1; i<=10000000; i++) {int aa = a.front();a.pop_front();int bb = b.front();b.pop_front();if(aa > bb) {a.pb(bb);a.pb(aa);}else {b.pb(aa);b.pb(bb);}if(a.empty() || b.empty()) {flag = 1;break;}//printf("a : %d b : %d\n",a.size(),b.size());}if(a.empty()) {printf("%d %d\n",i,2);}if(b.empty()) {printf("%d %d\n",i,1);}if(i > 10000000) printf("-1\n");return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440709.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

c 语言 while break,26 C 语言中的break和continue - C 语言基础教程

循环语句很好用&#xff0c;但是如果循环进行到一般想要跳出循环或者结束循环怎么办&#xff1f;那么那你需要 break 和 continue 语句。1. break 和 continue 的使用语法1.1 or 循环中使用 break 和 continuebreakfor (控制循环的变量; 循环判断条件; 循环变量增减变化){语句1…

android开发百度地图坐标偏差,利用百度地图Android sdk高仿微信发送位置功能及遇到的问题...

接触了百度地图开发平台半个月了&#xff0c;这2天试着模仿了微信给好友发送位置功能&#xff0c;对百度地图的操作能力又上了一个台阶我在实现这个功能的时候&#xff0c;遇到一些困难&#xff0c;可能也是别人将会遇到的困难&#xff0c;特在此列出1、在微信发送功能中&#…

kali linux 截图 软件,Kali-Linux-Tools-Interface:针对Kali Linux的图形化Web接口

Kali-Linux-Tools-Interface在当今这个信息时代&#xff0c;数据是最有价值的资产&#xff0c;因此&#xff0c;广大用户和企业已成为网络攻击的主要目标。众所周知&#xff0c;信息安全专业人员都会使用一系列技术工具来协助他们的活动。但是设置环境&#xff0c;安装这些工具…

android布局属性,Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline...

相信大家对LinearLayout已经相当熟悉&#xff0c;但你们是否了解它的属性baselineAligned呢&#xff1f;Android官方文档是这么描述的&#xff1a;那到底这个属性是做什么用的呢&#xff1f;baselineAligned:基准线对齐。首先要解释什么是基准线&#xff0c;这个在中文中不常见…

android取消自动调试模式吗,Android进入调试模式的三种技巧

8种机械键盘轴体对比本人程序员&#xff0c;要买一个写代码的键盘&#xff0c;请问红轴和茶轴怎么选&#xff1f;Android开发过程中难免会遇到各种问题&#xff0c;通常我们会通过打印Log日志或者Debug模式来分析问题。这里介绍下Android程序进入到Debug的多种方式&#xff0c;…

IMX6怎么移植最新Android,[IMX6Q][Android5.1]移植筆記 --- 無法掛載system文件系統

platform: imx6qos: Android5.1branch: l5.1.1_2.1.0-ga編譯好system image之后開機提示如下log&#xff0c;注意紅色部分:Freeing unused kernel memory: 432K (c0be3000 - c0c4f000)usb 1-1: USB disconnect, device number 2Console: switching to colour dummy device 80x3…

【POJ - 1456】Supermarket (贪心,优先队列 或并查集)

题干&#xff1a; A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precis…

【CodeForces - 558C】Amr and Chemistry(位运算,bfs,计数,思维,tricks)

题干&#xff1a; Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of ailiters. For this experiment, Amr has to mix all th…

我家云刷android系统教程,我家云刷机教程——小白详细版(篇二)

#大男孩的快乐#征稿活动火热进行中。只要投稿就有50金币等你拿&#xff0c;更有三千元乐高大奖与达人Z计划专属权益等待优秀的你~>活动详情戳这里<前两天发了一篇我家云的刷机教程&#xff0c;没想到大家这么有兴趣&#xff0c;讨论的异常激烈。看了大家的评论才发现之前…

【Loj - 515】贪心只能过样例(暴力,或01背包 + bitset)

题干&#xff1a; 题目描述 输入格式 第一行一个数 n。 然后 n 行&#xff0c;每行两个数表示 ai​,bi​。 输出格式 输出一行一个数表示答案。 样例 样例输入 5 1 2 2 3 3 4 4 5 5 6 样例输出 26 数据范围与提示 解题报告&#xff1a; 注意到要求统计种类数&#xf…

html loader的作用,webpack认识loader的作用

举例&#xff1a;如果希望在.html文件中使用style.css样式&#xff0c;我们以前只学习过一种方式&#xff1a;直接在.html中通过link的方式来引入 &#xff0c;这是传统的做法&#xff0c;在webpack语境下&#xff0c;我们将选择一条不同的道路&#xff1a;在js文件中引入了css…

5可视化数据大屏模板_可视化大屏模板分享

3个月前的一天&#xff0c;老板找到我&#xff1a;“小王&#xff0c;数据怎么才能产生让人惊艳的感觉呢&#xff1f;”我说&#xff1a;“肯定是用代码让程序员操作一下&#xff0c;再让设计师做一下配色&#xff0c;最好还能是数据实时变化的那种&#xff0c;简直就和电影里一…

c#12星座速配代码_白羊座今日运势|2020/12/11

整体运势&#xff1a;★★★☆☆爱情运势&#xff1a;★★☆☆☆事业运势&#xff1a;★★☆☆☆财富运势&#xff1a;★★★☆☆幸运数字&#xff1a;7速配星座&#xff1a;金牛座幸运颜色&#xff1a;橙色幸运时刻&#xff1a;12:00-14:00整体运势&#xff1a;接收的消息会比…

怎么去掉拼写检查的红线_发动机温度过高,水箱“开锅”,我们到底该怎么办?...

车子开久了&#xff0c;难免会出现一些小故障&#xff0c;今天我们就来说一下关于发动机水温过高的问题&#xff0c;这也是老司机常说的“开锅”。发动机水温正常情况是在80-90摄氏度之间&#xff0c;一旦超过这个温度&#xff0c;也就是水温表过了红线的时候&#xff0c;我们就…

【ZOJ - 2972】Hurdles of 110m (dp)

题干&#xff1a; In the year 2008, the 29th Olympic Games will be held in Beijing. This will signify the prosperity of China and Beijing Olympics is to be a festival for people all over the world as well. Liu Xiang is one of the famous Olympic athletes i…

格式说明_ISO11784/85 FDX-B动物芯片格式写码说明

植入式生物芯片口蹄疫、疯牛病、禽流感、非洲猪瘟的蔓延严重危及人类生命安全&#xff0c;引发了人们对动物性食品生产全过程安全追溯管理的重视。因此&#xff0c;有效地利用非接触式无线射频技术(RFID)对其进行控制成为有效的重要手段。一、国际动物识别标准介绍ISO 11784&am…

1至9填入九个方框内_防水涂料和施工堵漏的“五大技巧”和“九个细节”

防水涂料和施工堵漏的“五大技巧”和“九个细节”很多业主会在留言里问我家里水管堵了、房顶渗水怎么办&#xff0c;所以防水问题不可忽视。让您住的安心&#xff0c;您楼下的邻居也住的安心。对于防水问题&#xff0c;一定要在最初进行装修的时候就特别注意。下面这些是专业人…

限制 计算机中 某用户上网 win7,利用win7限制上网时间的方法

随着电脑的普及&#xff0c;很多家长为了让自己的孩子能有更广泛的知识&#xff0c;都给自己的孩子买了电脑&#xff0c;可现在很多孩子使用电脑却很少耗费在学习上&#xff0c;更多的时间是在娱乐&#xff0c;这样不仅影响学习而且还影响着视力&#xff0c;这样的问题相信困扰…

【ZOJ - 2976】Light Bulbs (枚举,暴力)

题干&#xff1a; Wildleopard had fallen in love with his girlfriend for 20 years. He wanted to end the long match for their love and get married this year. He bought a new house for his family and hired a company to decorate his house. Wildleopard and his…

为什么计算机编程以英语为主,为什么做编程都用英文,中文不行吗?听程序员解释完,总算明白了...

今天我们科普的话题是&#xff1a;为什么做编程都用英文&#xff0c;中文不行吗&#xff1f;听程序员解释完&#xff0c;总算明白了不知道大家最近有没有追过一部电视剧&#xff0c;它是《亲爱的热爱的》&#xff0c;由李现和杨紫主演的。主要讲述了这对情侣发生的浪漫爱情故事…