翻转 -- CodeForces - 56B
题目链接:
https://cn.vjudge.net/problem/25167/origin
思路:
这是一道水题,但是一开始思路有点问题。。
1000的数据大小,直接暴搜左开始第一个与i不等的下标,再从右开始搜第一与i不等的下标
然后用swap,或者reverse翻转一下,再进行对比就行。
有一个小坑就是原本就是顺序的话不行,因为题目明确要求必须翻转一次!
下面是AC代码:
#include <iostream>
#include <cstdio> using namespace std;
const int MX = 1e3+;
int a[MX]; int main()
{
bool flag = true;
int n;
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
int le = , ri = ;
for(int i = ; i <= n; ++i)
{
if(a[i] != i)
{
le = i;
break;
}
}
for(int i = n; i >= ; i--)
{
if(a[i] != i)
{
ri = i;
break;
}
}
if(le == && ri == ) flag = false; for(int i = le; i <= (le+ri)/; ++i)
{
swap(a[i], a[ri-i+le]);
//printf("%d %d\n", a[i], a[ri-i+le]);
} for(int i = ; i <= n; ++i)
{
//cout << a[i]; if(a[i] != i)
{
flag = false;
break;
} }
if(flag) printf("%d %d\n", le, ri);
else printf("0 0\n");
}
如有疑问,欢迎评论指出!
翻转 -- CodeForces - 56B的更多相关文章
- Codeforces Round #191 (Div. 2) A. Flipping Game【*枚举/DP/每次操作可将区间[i,j](1=<i<=j<=n)内牌的状态翻转(即0变1,1变0),求一次翻转操作后,1的个数尽量多】
A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round 56-B. Letters Rearranging(思维)
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- CFgym Board Queries (旋转、翻转简化)
http://codeforces.com/gym/100497 codeforces 2014-2015 CT S02E04: Codeforces Trainings Season 2 Episo ...
- Codeforces Beta Round #78 Div. 1 A
题目链接:http://codeforces.com/contest/98/problem/A 题意大意:给你6种颜色,这6种颜色可能相同也可能不同,把这几种颜色全涂在一个正方体表面,问有多少种涂法( ...
- codeforces 258div2 B Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有 ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #140 (Div. 1) D. The table 构造
D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...
- Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心
C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...
- codeforces C. Xor-tree
http://codeforces.com/problemset/problem/430/C 题意:在一棵上有n个节点,有n-1条边,在每一个节点上有一个值0或1,然后给你一个目标树,让你选择节点,然 ...
随机推荐
- redis的主从模式搭建及注意事项
前言:本文先分享下如何搭建redis的主从模式配置,以及主从模式配置的注意事项.后续会继续分享如何实现一个高可用的redis服务,redis的Sentinel 哨兵模式及集群搭建. 安装: 1,yum ...
- Day038--Python--Gevent , IO多路复用
1. 协程: gevent (遇到IO自动切换) import gevent import time from gevent import monkey; monkey.patch_all() # ...
- Linux下安装部署Samba共享盘的操作手册
简述 Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的 ...
- 批量ping 检测linux主机是否可以通
批量ping 检测linux主机是否可以通 # 1.配置列表 [root@db137 liweiwie]# cat /home/dbatlbb/script/liweiwie/ping_ip.txt ...
- CMDB资产管理系统开发【day27】:理解RESTful架构
理解RESTful架构 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件"采用客户端/服务器模式,建立在分布式体系上,通过互联网通信,具有高延时(hig ...
- jpa @onetomany 级联查询时会有重复数据,去重问题
自己是直接查出来然后利用set去重(自己感觉不是太好,不过能达到目的) List<CampaignDashboardDimensionDo> list = query.getResultL ...
- Html一些特殊字符(Html语法字符)的一种表达方式
空格 & & < < > > " " &qpos; '
- APPLE-SA-2019-3-25-5 iTunes 12.9.4 for Windows
APPLE-SA-2019-3-25-5 iTunes 12.9.4 for Windows iTunes 12.9.4 for Windows is now available and addres ...
- C#多态及接口
直接看代码吧 using System; using static System.Console; namespace ConsoleApp { //使用abstract,抽象类或方法,不能使用vir ...
- C#学习笔记-域用户认证(一)
public Boolean ValidateDomainUser(string Domain, string UserName, string Password) { DirectoryEntry ...