题目链接:

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的更多相关文章

  1. 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 ...

  2. Codeforces Round 56-B. Letters Rearranging(思维)

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  3. CFgym Board Queries (旋转、翻转简化)

    http://codeforces.com/gym/100497 codeforces 2014-2015 CT S02E04: Codeforces Trainings Season 2 Episo ...

  4. Codeforces Beta Round #78 Div. 1 A

    题目链接:http://codeforces.com/contest/98/problem/A 题意大意:给你6种颜色,这6种颜色可能相同也可能不同,把这几种颜色全涂在一个正方体表面,问有多少种涂法( ...

  5. codeforces 258div2 B Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有 ...

  6. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  7. 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 ...

  8. Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心

    C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...

  9. codeforces C. Xor-tree

    http://codeforces.com/problemset/problem/430/C 题意:在一棵上有n个节点,有n-1条边,在每一个节点上有一个值0或1,然后给你一个目标树,让你选择节点,然 ...

随机推荐

  1. C++:位操作基础篇之位操作全面总结

    位操作篇共分为基础篇和提高篇,基础篇主要对位操作进行全面总结,帮助大家梳理知识.提高篇则针对各大IT公司如微软.腾讯.百度.360等公司的笔试面试题作详细的解答,使大家能熟练应对在笔试面试中位操作题目 ...

  2. docker基本概念

    详细参考https://www.jianshu.com/p/9deb6f41d5bd

  3. python实现简单的百度云自动下载

    最近女同让我帮助从百度云下载200个文件,给了我连接和提取码,这种重复的工作不适合人做写了一个简单的爬虫 #coding=utf-8 ''' 自动填写提取码下载百度云资源 方法: for 读取文件中的 ...

  4. springmvc 项目单元测试

    对于web项目如果希望通过url来进行单元测试,但是启动服务器和建立http client 来进行测试非常麻烦,并且依赖网络环境.这样我们可以通过引入MockMvc进行测试. 一.引入jar包 < ...

  5. 流程控制if、while、for

    if判断   if判断想执行第一个条件,if后的判断必须是True 1 什么是if判断 判断一个条件如果成立则做...不成立则做....2 为何要有if判断 让计算机能够像人一样具有判断的能力3 如何 ...

  6. sqlmap基础入门超详细教程

    前言: 总算进入了自己喜欢的行业. 要时刻记得当初自己说过的话, 不忘初心. Come on! 资料: 感谢超哥分享的干货..  sqlmap干货点击直达 学习环境: 本次学习使用的是kali集成的s ...

  7. -bash: Chmod: command not found

    是增加该文件的所有者拥有运行权限 如果所有者是root ,还要加sudo chmod u+x drlinuxclient.bin (sudo) chmod u+x drlinuxclient.bin ...

  8. webpack学习记录 二

    开发网站 用polyfill(全局污染)  开发框架 用Runtime(局部污染) 在.babelrc文件中

  9. MinGW GCC 8.1.0 2018年5月2日 出炉啦

    MSYS_MinGW-w64_GCC_810_x86-x64.7z for x86 x64 59.0 MB发布日期: 2018-05-04 下载地址:https://sourceforge.net/p ...

  10. lua table表判断是否为空

    官方手册里早已经给了答案,那就是靠lua内置的next函数 即如此用: a = {} if next(a) == nil then next其实就是pairs遍历table时用来取下一个内容的函数. ...