Codeforces Round #304 (Div. 2)
来源:互联网 发布:ubuntu 查看系统日志 编辑:程序博客网 时间:2024/05/16 10:04
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.
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.
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.
42 1 32 4 2
6 2
31 22 1 3
-1
First sample:
Second sample:
码力题。。
#include<cstdio>#include<cstdlib>#include<iostream>#include<stack>#include<queue>#include<algorithm>#include<string>#include<cstring>#include<cmath>#include<vector>#include<map>#include<set>#define eps 1e-8#define zero(x) (((x>0?(x):-(x))-eps)#define mem(a,b) memset(a,b,sizeof(a))#define memmax(a) memset(a,0x3f,sizeof(a))#define pfn printf("\n")#define ll __int64#define ull unsigned long long#define sf(a) scanf("%d",&a)#define sf64(a) scanf("%I64d",&a)#define sf264(a,b) scanf("%I64d%I64d",&a,&b)#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)#define sf464(a,b,c,d) scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)#define sf564(a,b,c,d,ee) scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&ee)#define sf2(a,b) scanf("%d%d",&a,&b)#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)#define sf5(a,b,c,d,ee) scanf("%d%d%d%d%d",&a,&b,&c,&d,&ee)#define sff(a) scanf("%f",&a)#define sfs(a) scanf("%s",a)#define sfs2(a,b) scanf("%s%s",a,b)#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)#define sfd(a) scanf("%lf",&a)#define sfd2(a,b) scanf("%lf%lf",&a,&b)#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)#define sfc(a) scanf("%c",&a)#define ull unsigned long long#define pp pair<int,int>#define debug printf("***\n")#define pi 3.1415927#define mod 1000000007#define rep(i,a,b) for(int i=a;i<b;i++)const double PI = acos(-1.0);const double e = exp(1.0);const int INF = 0x7fffffff;;template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }bool cmpbig(int a, int b){ return a>b; }bool cmpsmall(int a, int b){ return a<b; }using namespace std;vector<int>vis[100010];vector<int>vis2[100010];int main(){ // freopen("data.in","r",stdin); //freopen("data.out" ,"w",stdout); int n; while(cin>>n) { //int k1,k2; int n,k11,k22; queue<int>q1,q2; sf(k11); while(!q1.empty()) q1.pop(); while(!q2.empty()) q2.pop(); rep(i,0,k11) { int pos; sf(pos); q1.push(pos); } rep(i,0,100010) { vis[i].clear(); vis2[i].clear(); } sf(k22); rep(i,0,k22) { int pos; sf(pos); q2.push(pos); } int cnt=0; while(1) { if(q1.empty()||q2.empty()) break; int fff=0,k=0,k2=0,fff2=0; int pos[20],pos2[20]; mem(pos,0),mem(pos2,0); while(!q1.empty()) { pos[k++]=q1.front(); q1.pop(); } rep(i,0,k) q1.push(pos[i]); while(!q2.empty()) { pos2[k2++]=q2.front(); q2.pop(); } rep(i,0,k2) q2.push(pos2[i]); int flagg; rep(i,0,cnt) { fff=0; fff2=0; flagg=0; if(vis[i].size()!=k) continue; if(vis2[i].size()!=k2) continue; rep(j,0,k) { if(vis[i][j]==pos[j]) fff++; else break; } rep(j,0,k2) { if(vis2[i][j]==pos2[j]) fff2++; else break; } if(fff2==k2) flagg++; if(fff==k) flagg++; if(flagg==2) { cout<<-1<<endl; return 0; } }// rep(i,0,k)// cout<<pos[i]<<" ";// pfn;// rep(i,0,k2)// cout<<pos2[i]<<" ";// pfn; //cout<<fff<<" "<<k<<" "<<fff2<<" "<<k2<<endl; rep(i,0,k) vis[cnt].push_back(pos[i]); rep(i,0,k2) vis2[cnt].push_back(pos2[i]); cnt++; int p1=q1.front(),p2=q2.front(); // cout<<p1<<" "<<p2<<endl; if(p1>p2) { q2.pop(); q1.pop(); q1.push(p2); q1.push(p1); } else { q1.pop(); q2.pop(); //cout<<q2.top()<<endl; q2.push(p1); q2.push(p2); } }// rep(i,0,cnt)// {// cout<<i+1<<endl;// rep(j,0,vis[i].size())// cout<<vis[i][j]<<" ";// pfn;// rep(j,0,vis2[i].size())// cout<<vis2[i][j]<<" ";// pfn;// } cout<<cnt<<" "; if(q1.empty()) cout<<2<<endl; else cout<<1<<endl; } return 0;}
- Codeforces Round #304 (Div. 2)
- Codeforces Round #304 (Div. 2)
- Codeforces Round #304 (Div. 2)
- Codeforces Round #304 (Div. 2)
- Codeforces Round #304 (Div. 2)
- Codeforces Round #304 (Div. 2) B
- Codeforces-B.Soldier and Badges - Codeforces Round #304 (Div. 2)
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Codeforces Round #121 (Div. 2)
- C#实现检测U盘的插拔
- POJ 2488 A Knight's Journey 搜索
- Java 打印1到最大的n位数
- SAP HANA使用XS和HTTP创建proxy
- CentOS、Ubuntu、Debian三个linux比较异同
- Codeforces Round #304 (Div. 2)
- Android自定义圆角矩形
- HTML5学习(一) 初始网页
- 学习笔记———《自动文档摘要评价方法---Edmundson和ROUGE》
- leetcode 494
- 【学习笔记】选择标识符
- unity3D---切换图片
- MQTT协议
- Web服务之基础知识