Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A - B

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

 

转载于:https://www.cnblogs.com/yyf0309/p/7170889.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值