zoukankan      html  css  js  c++  java
  • G

    题目大意:
    是一个洗牌游戏,首先给出两堆牌,s1,s2,先从s1上面拿一张牌再从s2上面拿一张牌依次往下可以洗好牌,然后把洗好的牌再分成两堆继续洗,直到这堆牌的顺序与给的顺序相同可以停止,当然如果洗不出给出来的顺序也可以停止
    看这题首先没有什么特别好的想法,先暴力一下试试吧,,,,,,,,,,,,,,,,,,,,,
    ///////////////////////////////////////////////////////////////
    时间竟然是0 ......真的就是一个模拟题,醉了
    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<queue>
    using namespace std;

    #define maxn 300

    char L[maxn], e[maxn];

    int Find(char s1[], char s2[], char s[], int C, int k)
    {
        int i, j;

        for(i=j=0; i<C; i++)
        {
            L[j++] = s2[i];
            L[j++] = s1[i];
        }

        if(strcmp(L, s) == 0)
            return k;

        if(k == 1)
            strcpy(e, L);
        if(k != 1 && strcmp(e, L) == 0)
            return -1;

        strncpy(s1, L, C);
        strncpy(s2, L+C, C);

        return Find(s1, s2, s, C, k+1);
    }

    int main()
    {
        int t=1, T;

        scanf("%d", &T);

        while(T--)
        {
            char s1[maxn]={0}, s2[maxn]={0}, s[maxn]={0};
            int C;

            scanf("%d%s%s%s", &C, s1, s2, s);

            memset(L, 0sizeof(L));

            int ans = Find(s1, s2, s, C, 1);

            printf("%d %d ", t++, ans);

        }

        return 0;

    } 

  • 相关阅读:
    解决谷歌高版本没有设置字符编码的选项的问题
    System.nanoTime与System.currentTimeMillis的区别
    jQuery学习笔记(一)
    linux问题
    阿里资源学习
    PHP-Gealman
    php-fpm
    GIT使用
    设置导出的excel数据
    CI框架, 参数验证
  • 原文地址:https://www.cnblogs.com/liuxin13/p/4648952.html
Copyright © 2011-2022 走看看