Codeforces Round #529 (Div. 3)

A. Repeating Cipher

Polycarp loves ciphers. He has invented his own cipher called repeating.

Repeating cipher is used for strings. To encrypt the string s=s1s2…sm (1≤m≤10), Polycarp uses the following algorithm:

he writes down s1 ones,
he writes down s2 twice,
he writes down s3 three times,

he writes down sm m times.
For example, if s=“bab” the process is: “b” → “baa” → “baabbb”. So the encrypted s=“bab” is “baabbb”.

Given string t — the result of encryption of some string s. Your task is to decrypt it, i. e. find the string s.

Input
The first line contains integer n (1≤n≤55) — the length of the encrypted string. The second line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is exactly n.

It is guaranteed that the answer to the test exists.

Output
Print such string s that after encryption it equals t.

Examples
input
6
baabbb
output
bab
input
10
ooopppssss
output
oops
input
1
z
output
z

题意:
给你一段加密的字符串,加密是如果未加密的是s=“bab” 则加密过程是: “b” → “baa” → “baabbb”. 给你baabbb 让你求出是bab;

解题思路:

“b” → “baa” → “baabbb”.
规律是 第一次 a 复制一次 第二次 b复制两次 则 k次 复制k次;
简单模拟一下即可

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
const int MM=1e5+5;
int n;
char s[MM];
int a[MM];
int main()
{
    int t;
    scanf("%d",&t);
    scanf("%s",s);
    int k=0;
    for(int i=0;i<t;)//
    {
        k++;//用来输出我们需要的字符
        cout<<s[i];
        i+=k;//删去第i次复制了i次的字符;
    }
    cout<<endl;
    return 0;
}

B. Array Stabilization
You are given an array a consisting of n integer numbers.

Let instability of the array be the following value: maxi=1nai−mini=1nai.

You have to remove exactly one element from this array to minimize instability of the resulting (n−1)-elements array. Your task is to calculate the minimum possible instability.

Input
The first line of the input contains one integer n (2≤n≤105) — the number of elements in the array a.

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

Output
Print one integer — the minimum possible instability of the array if you have to remove exactly one element from the array a.

Examples
input
4
1 3 3 7
output
2
input
2
1 100000
output
0
Note
In the first example you can remove 7 then instability of the remaining array will be 3−1=2.

In the second example you can remove either 1 or 100000 then instability of the remaining array will be 100000−100000=0 and 1−1=0 correspondingly.

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;
const int MM=1e5+5;
int n;
int a[MM<<1];
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%d",&a[i]);
    }
    if(t>2){
    sort(a,a+t);
    int sum=a[t-2]-a[0];
    int minn=a[t-1]-a[1];
    cout<<min(sum,minn);
    }
    else
        cout<<"0"<<endl;
    return 0;
}
全部评论

相关推荐

蚂蚁 基架java (n+6)*16 签字费若干
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
10-12 10:48
已编辑
秋招之苟:邻居家老哥19届双2硕大厂开发offer拿遍了,前几天向他请教秋招,他给我看他当年的简历,0实习实验室项目技术栈跟开发基本不沾边😂,我跟他说这个放在现在中厂简历都过不了
点赞 评论 收藏
分享
邮小鼠:粤嵌的项目水的要死 来我们学校带过课程实习 项目名字是车机终端 实际上就是写了了个gui 还是老师把代码发给你你改改的那种
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务