Codeforces Round #659 (Div. 2)部分题解

Codeforces Round #659 (Div. 2)部分题解

The length of the longest common prefix of two strings s=s1s2…sn and t=t1t2…tm is defined as the maximum integer k (0≤k≤min(n,m)) such that s1s2…sk equals t1t2…tk.

Koa the Koala initially has n+1 strings s1,s2,…,sn+1.

For each i (1≤i≤n) she calculated ai — the length of the longest common prefix of si and si+1.

Several days later Koa found these numbers, but she couldn’t remember the strings.

So Koa would like to find some strings s1,s2,…,sn+1 which would have generated numbers a1,a2,…,an. Can you help her?

If there are many answers print any. We can show that answer always exists for the given constraints.

Input
Each test contains multiple test cases. The first line contains t (1≤t≤100) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer n (1≤n≤100) — the number of elements in the list a.

The second line of each test case contains n integers a1,a2,…,an (0≤ai≤50) — the elements of a.

It is guaranteed that the sum of n over all test cases does not exceed 100.

Output
For each test case:

Output n+1 lines. In the i-th line print string si (1≤|si|≤200), consisting of lowercase Latin letters. Length of the longest common prefix of strings si and si+1 has to be equal to ai.

If there are many answers print any. We can show that answer always exists for the given constraints.

	很简单,直接自己创造一个很长的数组,再某一个部分改一个字母就好了
#include <iostream>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
string a, b, c;
int Maps[1005],maxsize = 0;
void cmpt(string &a, string &b,int size)
{
    b = a;
    b[size] = (b[size] + 1) > 'z' ? 'a' : b[size] + 1;
    cout << b << endl;
    a = b;
}
int main()
{
    //string a, b, c;
    int cases;
    cin >> cases;
    int t;
    a = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+
    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    while (cases--)
    {
        cin >> t;
        maxsize = 0;
        for (int i = 0; i < t; i++)
        {
            cin >> Maps[i];
            maxsize = max(Maps[i], maxsize);
        }
        cout << a << endl;
        for (int i = 0; i < t; i++)
        {
            cmpt(a, b, Maps[i]);
            //a = b;
        }
    }
}
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#define R register int
using namespace std;
const int maxn = 105;
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, maxIncreases, stayMaxdeep, now;//最大涨潮,可以待的最大深度
		bool flag = 1;
		scanf("%d%d%d", &n, &maxIncreases, &stayMaxdeep);
		now = -maxIncreases;
		for (R i = 1; i <= n; i++)
		{
			int deep, SubDeep;//深度,深度差
			scanf("%d", &deep);
			if (flag == 0)continue;
			SubDeep = stayMaxdeep - deep;//差值
			if (SubDeep < 0)flag = 0;//就连差值都是负数,必定淹死
			else
			{
				if (SubDeep >= maxIncreases)now = -maxIncreases;//如果可以待无限久,直到潮水是最低的时候走
				else now = max(now + 1, -SubDeep);//要么立即走,要么等到可以走的时候才走
				if (now > SubDeep)flag = 0;//查看这个值是不是和值大
			}
		}
		if (flag == 0)puts("No");
		else puts("Yes");
	}
	return 0;
}
他人代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=3e5+5;
ll a[M];
int main(){
	int t;
	cin>>t;
	while(t--){
		ll i,j,n,k,l;
		cin>>n>>k>>l;
		for(i=0;i<n;i++)
            cin>>a[i];
		ll flag=0,k1=k;
		for(i=0;i<n;i++){
		    ///留着安全
			if(a[i]+k<=l){
				k1=k;
				flag=0;
				continue;
			}
			///留着不安全
			if(flag==1)
                k1++;
			else
                k1=min(k1-1,l-a[i]);
			if(a[i]+k1>l)
                break;
			if(k1<0)
                break;
			if(k1==0)
                flag=1;
		}
		if(i==n)
            cout<<"Yes"<<"\n";
		else
            cout<<"No"<<"\n";
	}
	return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值