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;
}
全部评论

相关推荐

行云流水1971:这份实习简历的优化建议: 结构清晰化:拆分 “校园经历”“实习经历” 板块(当前内容混杂),按 “实习→校园→技能” 逻辑排版,求职意向明确为具体岗位(如 “市场 / 运营实习生”)。 经历具象化:现有描述偏流程,需补充 “动作 + 数据”,比如校园活动 “负责宣传” 可加 “运营公众号发布 5 篇推文,阅读量超 2000+,带动 300 + 人参与”;实习内容补充 “协助完成 XX 任务,效率提升 X%”。 岗位匹配度:锚定目标岗位能力,比如申请运营岗,突出 “内容编辑、活动执行” 相关动作;申请市场岗,强化 “资源对接、数据统计” 细节。 信息精简:删减冗余表述(如重复的 “负责”),用短句分点,比如 “策划校园招聘会:联系 10 + 企业,组织 200 + 学生参与,到场率达 85%”。 技能落地:将 “Office、PS” 绑定经历,比如 “用 Excel 整理活动数据,输出 3 份分析表;用 PS 设计 2 张活动海报”,避免技能单独罗列。 优化后需强化 “经历 - 能力 - 岗位需求” 的关联,让实习 / 校园经历的价值更直观。 若需要进一步优化服务,私信
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务