zoukankan      html  css  js  c++  java
  • Codeforce 546 C. Soldier and Cards

    题目链接:http://codeforces.com/contest/546/problem/C

    题目意思:1和2两个人分别有k1,k2张牌,分别去除最前面一张比较,不存在相同的牌,如果1胜那么先将2出的牌放入自己牌最后面,再把自己出的牌放入最后面。反复操作,最后如果有一人没牌那么比赛结束,输出进行了几次比赛和谁胜利。如果分不出胜负输出-1。

    分析:模拟比赛规则。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <map>
    #include <cstring>
    #include <queue>
    
    using namespace std;
    
    int a1[15];
    int a2[15];
    
    int main()
    {
        int n,n1,n2;
    
        while(scanf("%d",&n)!=EOF)
        {
            queue<int>q1;
            queue<int>q2;
    
            scanf("%d",&n1);
            for(int i=0;i<n1;i++)
            {
                scanf("%d",&a1[i]);
                q1.push(a1[i]);
            }
    
            scanf("%d",&n2);
            for(int i=0;i<n2;i++)
            {
                scanf("%d",&a2[i]);
                q2.push(a2[i]);
            }
            int k=0,flag=0;
            int x1,x2;
            while(1)
            {
                if(q1.empty()||q2.empty())
                    break;
                x1=q1.front();
                q1.pop();
                x2=q2.front();
                q2.pop();
                if(x1<x2)
                {
                    q2.push(x1);
                    q2.push(x2);
                }
                else
                {
                    q1.push(x2);
                    q1.push(x1);
                }
                k++;
                if(k>10000)
                {
                    printf("-1
    ");
                    flag=1;
                    break;
                }
            }
            if(flag==0)
            {
                if(q1.size())
                    printf("%d %d
    ",k,1);
                else
                    printf("%d %d
    ",k,2);
            }
    
        }
    
        return 0;
    }
  • 相关阅读:
    深入Activity生命周期(一)
    android APK 中英文对比(转)
    android中获得系统语言
    mime Contenttype(http head)(转)
    activity设置全屏
    Activity常用知识
    关于这次数学建模
    排列组合
    hdu 1003 笔记
    杂想
  • 原文地址:https://www.cnblogs.com/mengzhong/p/5003247.html
Copyright © 2011-2022 走看看