zoukankan      html  css  js  c++  java
  • codeforces 1203A Circle of Students(思维)

    思路很简单,用一个字符串保存原数组,对数组排序之后转成首尾相连的字符串,一个正序一个倒序再判断第一个字符串是不是他们中的子串就行了,这里顺便也练习了一下string的用法

    #include<cstdio>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<vector>
    #define TP 233333333333333
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    typedef pair<char, int> P2;
    const int maxn = 1000005;
    int arr[maxn];
    int main(void) {
        int n;
        cin >> n;
        while(n--) {
            int m;
            cin >> m;
            string s1, s2, rs;
            for (int i = 0; i<m; i++) {
                cin >> arr[i];
                s1 += (arr[i] + '0');
            }
            sort(arr, arr+m);
            for (int i = 0; i<m; i++) 
                s2 += (arr[i] + '0');
            s2 = s2 + s2;
            rs = s2;
            reverse(rs.begin(), rs.end());
            if (s2.find(s1) != string::npos || rs.find(s1) != string::npos)
                cout << "YES\n";
            else 
                cout << "NO\n";
        }
        return 0;
    }
    
  • 相关阅读:
    flask 指定前端文件路径以及静态文件路径
    pycharm git修改密码
    Web应用搭建
    python学习
    python解析jSON文件
    通过DLNA将电脑视频投射到电视屏幕
    U盘自动复制文件
    kali PIN码破解
    mdk3洪水攻击教程
    sqlmap(网站数据库注入)
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12266525.html
Copyright © 2011-2022 走看看