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
#include
#include
#include
#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 
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>a[i];
		ll flag=0,k1=k;
		for(i=0;il)
                break;
			if(k1<0)
                break;
			if(k1==0)
                flag=1;
		}
		if(i==n)
            cout<<"Yes"<<"\n";
		else
            cout<<"No"<<"\n";
	}
	return 0;
}

你可能感兴趣的:(刷题心得,算法)