zoukankan      html  css  js  c++  java
  • Codeforces-940D. Alena And The Heater

    传送门

    给定n(5 ≤ n ≤ 105,接着给出长度为n的序列a和字符串b

    b1 = b2 = b3 = b4 = 0.

    For all 5 ≤ i ≤ n

    • bi = 0 if ai, ai - 1, ai - 2, ai - 3, ai - 4 > r and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 1
    • bi= 1 if ai, ai - 1, ai - 2, ai - 3, ai - 4 < l and bi - 1 = bi - 2 = bi - 3 = bi - 4 = 0
    • bi = bi - 1 otherwise

    则b中出现00001可确定l下界,11110可确定r上界

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 using namespace std;
     5 
     6 const int maxn = 1e5 + 10;
     7 int A[maxn];
     8 char S[maxn];
     9 int n;
    10 
    11 int _min(int i) {
    12     int t = A[i];
    13     for (int j = i - 1; j > i - 5; j--) {
    14         t = min(t, A[j]);
    15     }
    16     return t;
    17 }
    18 
    19 int _max(int i) {
    20     int t = A[i];
    21     for (int j = i - 1; j > i - 5; j--) {
    22         t = max(t, A[j]);
    23     }
    24     return t;
    25 }
    26 
    27 int main() {
    28     scanf("%d", &n);
    29     for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    30     scanf("%s", S);
    31     int zero = 0, one = 0;
    32     int r = 1e9;
    33     int l = -r;
    34     for (int i = 0; i < n; i++) {
    35         if (S[i] == '0') {
    36             if (one >= 4) {
    37                 r = min(r, _min(i) - 1);
    38             }
    39             one = 0;
    40             zero++;
    41         } else if (S[i] == '1') {
    42             if (zero >= 4) {
    43                 l = max(l, _max(i) + 1);
    44             }
    45             zero = 0;
    46             one++;
    47         }
    48     }
    49     printf("%d %d
    ", l, r);
    50     return 0;
    51 }
  • 相关阅读:
    MySql触发器简介
    MySQL存储过程
    MySQL自定义函数
    MySql视图
    MySQL增删改
    MySQL内联和外联查询
    MySql运算符
    SQL scripts
    Adding Swagger to Web API project
    Unable to get setting value Parameter name: profileName
  • 原文地址:https://www.cnblogs.com/xFANx/p/8570777.html
Copyright © 2011-2022 走看看