zoukankan      html  css  js  c++  java
  • Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A

    Array of integers is unimodal, if:

    • it is strictly increasing in the beginning;
    • after that it is constant;
    • after that it is strictly decreasing.

    The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.

    For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal:[5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].

    Write a program that checks if an array is unimodal.

    Input

    The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.

    The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000) — the elements of the array.

    Output

    Print "YES" if the given array is unimodal. Otherwise, print "NO".

    You can output each letter in any case (upper or lower).

    Examples
    input
    6
    1 5 5 5 4 2
    output
    YES
    input
    5
    10 20 30 20 10
    output
    YES
    input
    4
    1 2 1 2
    output
    NO
    input
    7
    3 3 3 3 3 3 3
    output
    YES
    Note

    In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).


      题目大意 给定一个数组,判断它是否是单峰的。一个数组是单峰的是指它的最大值出现的位置是连续的,其左侧严格递增,右侧严格递减。

      先找出数组中的最大值,然后while到遇到最大值停止(边判断),然后while把最大值的连续一段水掉,然后再while到数组结尾。

    Code

     1 /**
     2  * Codeforces
     3  * Problem#831A
     4  * Accepted
     5  * Time:15ms
     6  * Memory:2052k
     7  */
     8 #include <iostream>
     9 #include <cstdio>
    10 #include <ctime>
    11 #include <cmath>
    12 #include <cctype>
    13 #include <cstring>
    14 #include <cstdlib>
    15 #include <fstream>
    16 #include <sstream>
    17 #include <algorithm>
    18 #include <map>
    19 #include <set>
    20 #include <stack>
    21 #include <queue>
    22 #include <vector>
    23 #include <stack>
    24 #include <cassert>
    25 #ifndef WIN32
    26 #define Auto "%lld"
    27 #else
    28 #define Auto "%I64d"
    29 #endif
    30 using namespace std;
    31 typedef bool boolean;
    32 const signed int inf = (signed)((1u << 31) - 1);
    33 const signed long long llf = (signed long long)((1ull << 61) - 1);
    34 const double eps = 1e-6;
    35 const int binary_limit = 128;
    36 #define smin(a, b) a = min(a, b)
    37 #define smax(a, b) a = max(a, b)
    38 #define max3(a, b, c) max(a, max(b, c))
    39 #define min3(a, b, c) min(a, min(b, c))
    40 template<typename T>
    41 inline boolean readInteger(T& u){
    42     char x;
    43     int aFlag = 1;
    44     while(!isdigit((x = getchar())) && x != '-' && x != -1);
    45     if(x == -1) {
    46         ungetc(x, stdin);    
    47         return false;
    48     }
    49     if(x == '-'){
    50         x = getchar();
    51         aFlag = -1;
    52     }
    53     for(u = x - '0'; isdigit((x = getchar())); u = (u << 1) + (u << 3) + x - '0');
    54     ungetc(x, stdin);
    55     u *= aFlag;
    56     return true;
    57 }
    58 
    59 int n;
    60 int *a;
    61 int maxv = 0;
    62 
    63 inline void init() {
    64     readInteger(n);
    65     a = new int[(n + 1)];
    66     for(int i = 1; i <= n; i++) {
    67         readInteger(a[i]);
    68         smax(maxv, a[i]);
    69     }
    70 }
    71 
    72 inline void solve() {
    73     int last;
    74     int i = 1;
    75     while(a[i] < maxv) {
    76         if(i != 1) {
    77             if(a[i - 1] >= a[i]) {
    78                 puts("NO");
    79                 return;
    80             }
    81         }
    82         i++;
    83     }
    84     while(a[i] == maxv && i <= n) i++;
    85     while(i <= n) {
    86         if(a[i] >= a[i - 1]) {
    87             puts("NO");
    88             return;
    89         }
    90         i++;
    91     }
    92     puts("YES");
    93 }
    94 
    95 int main() {
    96     init();
    97     solve();
    98     return 0;
    99 }
    Problem A

    There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.

    You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order.

    You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.

    Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters.

    Input

    The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout.

    The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout.

    The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000.

    Output

    Print the text if the same keys were pressed in the second layout.

    Examples
    input
    qwertyuiopasdfghjklzxcvbnm
    veamhjsgqocnrbfxdtwkylupzi
    TwccpQZAvb2017
    output
    HelloVKCup2017
    input
    mnbvcxzlkjhgfdsapoiuytrewq
    asdfghjklqwertyuiopzxcvbnm
    7abaCABAABAcaba7
    output
    7uduGUDUUDUgudu7

      题目大意 给定字母的映射,然后映射一个字符串,非字母字符保留。

      依题意乱搞即可。

    Code

     1 /**
     2  * Codeforces
     3  * Problem#831B
     4  * Accepted
     5  * Time:15ms
     6  * Memory:2052k
     7  */
     8 #include <iostream>
     9 #include <cstdio>
    10 #include <ctime>
    11 #include <cmath>
    12 #include <cctype>
    13 #include <cstring>
    14 #include <cstdlib>
    15 #include <fstream>
    16 #include <sstream>
    17 #include <algorithm>
    18 #include <map>
    19 #include <set>
    20 #include <stack>
    21 #include <queue>
    22 #include <vector>
    23 #include <stack>
    24 #include <cassert>
    25 #ifndef WIN32
    26 #define Auto "%lld"
    27 #else
    28 #define Auto "%I64d"
    29 #endif
    30 using namespace std;
    31 typedef bool boolean;
    32 const signed int inf = (signed)((1u << 31) - 1);
    33 const signed long long llf = (signed long long)((1ull << 61) - 1);
    34 const double eps = 1e-6;
    35 const int binary_limit = 128;
    36 #define smin(a, b) a = min(a, b)
    37 #define smax(a, b) a = max(a, b)
    38 #define max3(a, b, c) max(a, max(b, c))
    39 #define min3(a, b, c) min(a, min(b, c))
    40 template<typename T>
    41 inline boolean readInteger(T& u){
    42     char x;
    43     int aFlag = 1;
    44     while(!isdigit((x = getchar())) && x != '-' && x != -1);
    45     if(x == -1) {
    46         ungetc(x, stdin);    
    47         return false;
    48     }
    49     if(x == '-'){
    50         x = getchar();
    51         aFlag = -1;
    52     }
    53     for(u = x - '0'; isdigit((x = getchar())); u = (u << 1) + (u << 3) + x - '0');
    54     ungetc(x, stdin);
    55     u *= aFlag;
    56     return true;
    57 }
    58 
    59 int n;
    60 char a[1005];
    61 char b[1005];
    62 map<char, char> ctc;
    63 
    64 const char utl = 'a' - 'A'; 
    65 
    66 inline void init() {
    67     gets(a);
    68     gets(b);
    69     for(int i = 0; a[i]; i++) {
    70         ctc[a[i]] = b[i];
    71         ctc[a[i] - utl] = b[i] - utl; 
    72     }
    73 }
    74 
    75 inline void solve() {
    76     gets(a);
    77     for(int i = 0; a[i]; i++) {
    78         if((a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z')) {
    79             putchar(ctc[a[i]]);
    80         } else {
    81             putchar(a[i]);
    82         }
    83     }
    84 }
    85 
    86 int main() {
    87     init();
    88     solve();
    89     return 0;
    90 }
    Problem B
  • 相关阅读:
    双栈排序
    Koishi Loves Segments
    [USACO14FEB] Cow Decathlon 牛的十项全能
    [HNOI2016]网络
    koishi的数学题
    邦邦的大合唱站队
    #613(div2)
    Educational Codeforces Round 77
    #Hello 2020
    #601 (Div. 2)
  • 原文地址:https://www.cnblogs.com/yyf0309/p/7170889.html
Copyright © 2011-2022 走看看