• [模拟]Codeforces Circle of Students


    Circle of Students
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are nn students standing in a circle in some order. The index of the ii-th student is pipi. It is guaranteed that all indices of students are distinct integers from 11 to nn (i. e. they form a permutation).

    Students want to start a round dance. A clockwise round dance can be started if the student 22 comes right after the student 11 in clockwise order (there are no students between them), the student 33 comes right after the student 22 in clockwise order, and so on, and the student nncomes right after the student n1n−1 in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student ii should be right after the student i1i−1 in counterclockwise order (this condition should be met for every ii from 22 to nn).

    For example, if the indices of students listed in clockwise order are [2,3,4,5,1][2,3,4,5,1], then they can start a clockwise round dance. If the students have indices [3,2,1,4][3,2,1,4] in clockwise order, then they can start a counterclockwise round dance.

    Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle.

    You have to answer qq independent queries.

    Input

    The first line of the input contains one integer qq (1q2001≤q≤200) — the number of queries. Then qq queries follow.

    The first line of the query contains one integer nn (1n2001≤n≤200) — the number of students.

    The second line of the query contains a permutation of indices p1,p2,,pnp1,p2,…,pn (1pin1≤pi≤n), where pipi is the index of the ii-th student (in clockwise order). It is guaranteed that all pipi are distinct integers from 11 to nn (i. e. they form a permutation).

    Output

    For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".

    Example
    input
    Copy
    5
    4
    1 2 3 4
    3
    1 3 2
    5
    1 2 3 5 4
    1
    1
    5
    3 2 1 5 4
    
    output
    Copy
    YES
    YES
    NO
    YES
    YES

    模拟题,长度只有200,看能不能完整绕一圈就好了,中间要两两之差绝对值为1且保持单调性,可以允许一次单调性的改变

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int amn=1e3+5;
     4 int a[amn];
     5 int main(){
     6     int q,n;
     7     cin>>q;
     8     while(q--){
     9         cin>>n;
    10         for(int i=1;i<=n;i++)cin>>a[i];
    11         int valid=1;
    12         if(n>1){
    13             int ed=n,f=a[2]-a[1],fr=1;
    14             for(int i=1;i!=ed;){
    15                 int nex=i+1<=n?i+1:1;
    16                 if(abs(a[i]-a[nex])!=1){
    17                     if(fr){ed=i,fr=0;f=(i==1)?-f:f;i=(i+1<=n)?i+1:1;continue;}
    18                     else {valid=0;break;}
    19                 }
    20                 if(i==ed)break;
    21                 if(f>0){
    22                     if(abs(a[i]-a[nex])!=1||a[nex]-a[i]<0){valid=0;break;}
    23                 }
    24                 else if(f<0){
    25                     if(abs(a[i]-a[nex])!=1||a[nex]-a[i]>0){valid=0;break;}
    26                 }
    27                 else {valid=0;break;}
    28                 i=(i+1<=n)?i+1:1;
    29             }
    30         }
    31         if(valid)cout<<"YES
    ";
    32         else cout<<"NO
    ";
    33     }
    34 }
    35 /***
    36 模拟题,长度只有200,看能不能完整绕一圈就好了,中间要两两之差绝对值为1且保持单调性,可以允许一次单调性的改变
    37 51234
    38 15432
    39 ***/
  • 相关阅读:
    Logstash:Logstash-to-Logstash 通信
    Elastic:Sense chrome
    Elasticsearch:Elasticsearch-head
    Beats:运用 Filebeat 来对微服务 API 进行分析
    Kibana:如何让用户匿名访问 Kibana 中的 Dashboard
    Beats:为 Beats => Logstash => Elasticsearch 架构创建 template 及 Dashboard
    使用kuboard界面配置springcloud的其中一个模块设置环境变量,使用nacos配置地址等有关设置
    Security Context
    使用kuboard界面管理k8s集群时使用ConfigMap挂载挂载到pod容器中,映射成一个文件夹
    通过nginx转发rabbitmq访问手动添加队列的时候报错:Management API returned status code 405
  • 原文地址:https://www.cnblogs.com/Railgun000/p/11349878.html
Copyright © 2020-2023  润新知