[模拟]Codeforces Circle of Students
2 seconds
256 megabytes
standard input
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 n−1n−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 i−1i−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.
The first line of the input contains one integer qq (1≤q≤2001≤q≤200) — the number of queries. Then qq queries follow.
The first line of the query contains one integer nn (1≤n≤2001≤n≤200) — the number of students.
The second line of the query contains a permutation of indices p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤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).
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".
5
4
1 2 3 4
3
1 3 2
5
1 2 3 5 4
1
1
5
3 2 1 5 4
YES
YES
NO
YES
YES
模拟题,长度只有200,看能不能完整绕一圈就好了,中间要两两之差绝对值为1且保持单调性,可以允许一次单调性的改变
#include<bits/stdc++.h>
using namespace std;
const int amn=1e3+;
int a[amn];
int main(){
int q,n;
cin>>q;
while(q--){
cin>>n;
for(int i=;i<=n;i++)cin>>a[i];
int valid=;
if(n>){
int ed=n,f=a[]-a[],fr=;
for(int i=;i!=ed;){
int nex=i+<=n?i+:;
if(abs(a[i]-a[nex])!=){
if(fr){ed=i,fr=;f=(i==)?-f:f;i=(i+<=n)?i+:;continue;}
else {valid=;break;}
}
if(i==ed)break;
if(f>){
if(abs(a[i]-a[nex])!=||a[nex]-a[i]<){valid=;break;}
}
else if(f<){
if(abs(a[i]-a[nex])!=||a[nex]-a[i]>){valid=;break;}
}
else {valid=;break;}
i=(i+<=n)?i+:;
}
}
if(valid)cout<<"YES\n";
else cout<<"NO\n";
}
}
/***
模拟题,长度只有200,看能不能完整绕一圈就好了,中间要两两之差绝对值为1且保持单调性,可以允许一次单调性的改变
51234
15432
***/
[模拟]Codeforces Circle of Students的更多相关文章
- CF #579 (Div. 3) A.Circle of Students
A. Circle of Students time limit per test2 seconds memory limit per test256 megabytes inputstandard ...
- codeforces 1287A -Angry Students(模拟)
It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torz ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- 模拟 Codeforces Round #203 (Div. 2) C. Bombs
题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
- 模拟 Codeforces Round #288 (Div. 2) A. Pasha and Pixels
题目传送门 /* 模拟水题:给定n*m的空白方格,k次涂色,将(x,y)处的涂成黑色,判断第几次能形成2*2的黑色方格,若不能,输出0 很挫的判断四个方向是否OK */ #include <cs ...
- 【Codeforces 332C】Students' Revenge
Codeforces 332 C 我爱对拍,对拍使我快乐... 题意:有\(n\)个议题,学生们会让议会同意\(p\)个,其中主席会执行\(k\)个, 每一个议题执行后主席会掉\(a_i\)的头发,不 ...
随机推荐
- 编写高质量 Objective-C 代码
第一章 熟悉 Objective-C 第一条:了解 Objective-C 起源 Objective-C 是 C 语言动态性扩充.使用"消息结构"而非"函数调用" ...
- (转)Linux设备驱动之HID驱动 源码分析
//Linux设备驱动之HID驱动 源码分析 http://blog.chinaunix.net/uid-20543183-id-1930836.html HID是Human Interface De ...
- C++扬帆远航——12(抓小偷)
/* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:zhaoxiaotou.cpp * 作者:常轩 * 微信公众号: ...
- 压力测试(九)-Jmeter压测课程总结和架构浅析
安装常见问题 1.问题 [root@iZwz95j86y235aroi85ht0Z bin]# ./jmeter-server Created remote object: UnicastServer ...
- TOMCAT封装DBCP
## 数据源 ## #Tomcat封装的DBCP: >> 基本知识: tomcat在默认情况下已经集成了DBCP: >> JNDI: |-- 基本概念: 在tomcat启动的时 ...
- HandlerInterceptor ModelAndView null springMVC @ResponseBody
本文来源https://blog.csdn.net/whiteforever/article/details/77457109 用了@RestController或者@ResponseBody注解之后 ...
- 【30分钟学完】canvas动画|游戏基础(6):坐标旋转探究
前言 本篇主要讲坐标旋转及其应用,这是编程动画必不可少的技术. 阅读本篇前请先打好前面的基础. 本人能力有限,欢迎牛人共同讨论,批评指正. 坐标旋转 模拟场景:已知一个中心点(centerX,cent ...
- proxyTable的配置
在dev环境下面: proxyTable: { '/api': { target: 'http://api.douban.com/v2', //主域名,以前我都写192.168.2.57:80,这里跨 ...
- Error : Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
记录一下: 报错:# Error : Failed to get convolution algorithm. This is probably because cuDNN failed to ini ...
- 学以致用:手把手教你撸一个工具库并打包发布,顺便解决JS浮点数计算精度问题
本文讲解的是怎么实现一个工具库并打包发布到npm给大家使用.本文实现的工具是一个分数计算器,大家考虑如下情况: \[ \sqrt{(((\frac{1}{3}+3.5)*\frac{2}{9}-\fr ...