CodeForces 451B

#include <iostream>

#include <algorithm>

using namespace std;

#define max 100010

int a[max],b[max];

bool cmp(int a,int b){

  return a<b;

}

int main(){

int n;

while(cin>>n){

  for(int i=0;i<n;i++){

    cin>>a[i]; b[i]=a[i];

  }

  sort(a,a+n,cmp);

  int st=0,en=0;

  bool ok1=true,ok2=true;

  for(int i=0;i<n;i++){

    if(a[i]!=b[i]&&ok1){

      st=i;ok1=false;

    }

    if(a[n-1-i]!=b[n-1-i]&&ok2){

      en=n-1-i;

      ok2=false;

    }

    if(!ok1&&!ok2)break;

  }

//cout<<st<<en<<endl;

  bool ok3=true;

  for(int i=st;i<en;i++){

    if(b[i]<b[i+1]){ok3=false;break;}

  }

  if(ok3)cout<<"yes\n"<<st+1<<" "<<en+1<<endl;

  else cout<<"no"<<endl;

}

return 0;

}

CodeForces 451B,布布扣,bubuko.com

时间: 07-24

CodeForces 451B的相关文章

CodeForces 451B Sort the Array

Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a b

CodeForces 451B (翻转一次递减子序列得到递增序列) 简单题

题目大意:判断能否找到递减的子列,将其翻转后得到的整个数列递增,只能找一次,最后输出,如果能还要输出翻转的首尾位 置,注意数数组下标,不是首尾的数,当然如果本来数列就递增,就随便找个数翻一下. 我的方法是直接模拟,直接从a[0]开始寻找递减序列,然后判断递减序列翻转后能否构成递增序列. #include<stdio.h> int n,a[100005]; int main() { int i,j,h; bool bo=true; scanf("%d",&n); fo

CSU-ACM暑假集训基础组训练赛(2) 解题报告

Problem A Codeforces 451A •题意:给你n+m根筷子,将他们分别水平.垂直放置,形成n*m个节点.两个人轮流选择一个点,将穿过这个点的两根筷子拿走,谁可以逼迫对方率先无法继续操作,谁就获胜,问获胜的是先手还是后手. •找规律即可.n,m中较小的那个数是奇数,先手胜,否则后手胜. 1 #include <cstdio> 2 int main(){ 3 int a,b; 4 scanf("%d%d",&a,&b); 5 a = a <

【模拟】【codeforces】451B Sort the Array

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=52107 给出一个数列,问截取哪一部分连续子列进行翻转可以使整个数列升序排列, 如果有这样的字串输出yes和截取位置,没有输出no 就是先记录原始位置进行排序,之后一旦发现一个元素排序后更改了位置那它就被翻转过. 完全逆序排列应该是排序后原先的位置依次减1,这样得到被翻转的前后位置. 之后继续扫描,如果还有位置不对的,说明翻转一段不能完成,输出no 1 #include<bi

Codeforces Round #258 (Div. 2) 小结

A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行列中最小的一个为奇数,那么Akshat赢,否则Malvika赢. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace

Codeforces Round #258

A.Game With Sticks 就发现选定一个点之后,会删除相应的行列,即n-1,m-1,所以只需要看min(n,m)是基是偶 #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; int n, m; int main() { #ifdef LOCAL freopen("451A.in", "r", stdin); #end

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th