翻转 -- 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,然后给你一个目标树,让你选择节点,然 ...
随机推荐
- NEED TO DO
任务清单 计算几何 KDtree 容斥 后缀自动机套数据结构 FFT 四边形不等式/决策单调性优化 欧拉路 KM算法 BM算法 数论 min25筛 后缀数组 吉司机线段树 生成函数 ...
- python 第一课 helloworld
#!/usr/bin/env python #-*-coding:utf-8-*- #以上是配置编写环境的开始 #第一行env表示运行当前环境变量内的python版本(2.x or 3.x) #第二行 ...
- Chrome浏览器中autocomplete="off"不起作用解决方案
多数浏览器默认会缓存input的值,只有使用ctl+F5强制刷新的才可以清除缓存记录. 如果不想让浏览器缓存input的值,有2种方法: 方法一: 在不想使用缓存的input中添加 autocompl ...
- java poi 操作ppt
java poi 操作ppt 可以参考: https://www.w3cschool.cn/apache_poi_ppt/apache_poi_ppt_installation.html http:/ ...
- burp suite 基础入门超详细教程
介绍: 都是我个人了解到的信息,,分享给大家 欢迎指正 burp suite 被誉为web安全工具中的瑞士军刀. 大家知道,瑞士军刀,都是体积小,功能强悍,.西方军队的标配.说这么多,只是想强调这款工 ...
- PHP循环语句深度理解分析——while, for, foreach, do while
循环结构 一.while循环 while(表达式) { 循环体;//反复执行,直到表达式为假 } 代码: $index = 1; while ($index<5) { ...
- React Router v4 页面传值的三种方法
传值方法 1.props.params 使用React router定义路由时,我们可以给指定一个path,然后指定通配符可以携带参数到指定的path: <Route path='/user/: ...
- nginx 中用 sed 批量增加配置文件内容
#!/bin/bash confs=`ls /etc/nginx/conf.d/cms_vhosts/` cd /etc/nginx/conf.d/cms_vhosts for log in $con ...
- Shell 自动化部署免密登录
1 .配置主机名称 参考:Linux 修改主机名 和 ip 映射关系 2 . 编写脚本 root.sh 内容 #!/bin/bash SERVERS="hadoop0 hadoop1 had ...
- 推荐安全且匿名的邮箱 ProtonMail -- PGP算法
==以前一直以为平时所用的邮箱是绝对安全的,没有深思它的安全性. 然而你要“犯罪”不留任何痕迹的话,呵呵. 国内应该没有类似 ProtonMail 的邮箱,-->去了解一下 ========== ...