• codeforces 258div2 B Sort the Array


    题目链接:http://codeforces.com/contest/451/problem/B

    解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列。

    我的做法有点不一样,我是将原来的序列先按照升序排好序,然后分别从头和尾开始扫,找到跟原来的数组不一样的子序列的区间,然后判断这个区间是不是原来的区间翻转而来。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 typedef long long INT;
     7 const int maxn = 100000+5;
     8 INT que[maxn],que2[maxn];
     9 int main()
    10 {
    11     int n;
    12     while(scanf("%d",&n)!=EOF)
    13     {
    14         for(int i = 1;i <= n;++i)
    15         {
    16             scanf("%lld",&que[i]);
    17             que2[i] = que[i];
    18         }
    19         sort(que+1,que+n+1);
    20         int l = 1;
    21         for(;l < n;++l)
    22         if(que[l] == que[l+1])
    23         break;
    24         if(l < n)
    25         {
    26             printf("no
    ");
    27             continue;
    28         }
    29         int s = 1,e = n;
    30         while(s <= n && que[s] == que2[s]) s++;
    31         if(s > n)
    32         {
    33             printf("yes
    1 1
    ");
    34             continue;
    35         }
    36         while(e >= 1 && que[e] == que2[e]) e--;
    37         int x = s,y = e;
    38         while(s <= y && que[s] == que2[e]) s++,e--;
    39         printf(s > y? "yes
    %d %d
    ":"no
    ",x,y);
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    Go 命令行参数,JSON 序列化与反序列化
    Go 文件操作
    Go 多态
    Go 接口
    Go 面向对象三大特性
    Go 面向对象编程应用
    Go 结构体方法
    Go 面向对象之结构体
    Go Map
    vue安装 vue-cli安装
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3868091.html
Copyright © 2020-2023  润新知