zoukankan      html  css  js  c++  java
  • POJ3087 Shuffle'm Up(模拟)

    题目链接

    AC代码如下;

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <string>
    #include <queue>
    #include <algorithm>
    #include <map>
    #include <ctype.h>
    #include <set>
    
    using namespace std;
    
    const int maxn = 1000+10;
    
    int main() {
        int T, n, cn; bool flag;
        char s1[maxn], s2[maxn], s3[maxn], s[maxn];
        
        scanf("%d", &T);
    
        for(int kase=1; kase<=T; kase++) {
          set<string> st;
          
          cn = 0; flag = true;
        
          scanf("%d", &n);
    
          scanf("%s%s%s", s1, s2, s3);
        
          while(true) {
              cn++;
              for(int i=0; i<n; i++) {
                s[2*i] = s2[i];
                s[2*i+1] = s1[i];
             } 
        s[
    2*n] = '';    if(strcmp(s, s3) == 0) {      break;    }    if(st.count(s) != 0) {      flag = false;      break;    }    st.insert(s);    for(int i=0; i<n; i++) {      s1[i] = s[i];   }    for(int i=n; i<2*n; i++) {      s2[i-n] = s[i];   }   s1[n] = s2[n] = '';    }    printf("%d ", kase);    if(flag) printf("%d ", cn);    else printf("-1 "); } return 0; }
  • 相关阅读:
    docker-compose
    Cassandra
    npm常用命令
    k8s linux win10
    wsl2 docker 迁移
    docker http 代理
    mysql查看当前所有的数据库和索引大小
    mybatis 遍历list拼接 or查询
    es head crud
    nginx 代理转发mysql
  • 原文地址:https://www.cnblogs.com/tanhehe/p/3271984.html
Copyright © 2011-2022 走看看