zoukankan      html  css  js  c++  java
  • BZOJ2882 工艺

    hzwer:"输出最小表示"

    感觉就是kmp的思想呢?

     1 /**************************************************************
     2     Problem: 2882
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:492 ms
     7     Memory:1976 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <algorithm>
    12  
    13 using namespace std;
    14 const int N = 300005;
    15  
    16 int n;
    17 int a[N];
    18  
    19 int work() {
    20     int i = 0, j = 1, k = 0, tmp;
    21     while (i < n && j < n && k < n) {
    22         tmp = a[(i + k) % n] - a[(j + k) % n];
    23         if (!tmp) ++k;
    24         else {
    25             if (tmp > 0) i += k + 1;
    26             else j += k + 1;
    27             if (i == j) ++i;
    28             k = 0;
    29         }
    30     }
    31     return min(i, j);
    32 }
    33  
    34 int main() {
    35     int i, st;
    36     scanf("%d", &n);
    37     for (i = 0; i < n; ++i)
    38         scanf("%d", a + i);
    39     st = work();
    40     printf("%d", a[st % n]);
    41     for (i = 1; i < n; ++i)
    42         printf(" %d", a[(st + i) % n]);
    43     return 0;
    44 }
    View Code
    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    Nginx使用
    MySQL 分区
    php PDO预处理
    php
    php
    linux 下编译安装MySQL
    php 工厂模式
    MySQL 权限管理
    hadoop集群安装20181016(20111130:前面太忙,没有写完,后面继续)
    JavaScript函数参数翻转——连接多个数组——zip、zipwith
  • 原文地址:https://www.cnblogs.com/rausen/p/4167799.html
Copyright © 2011-2022 走看看