Deltix Round,Spring2021(open for everyone,rated,Div.1+Div.2)

Posted 晁棠

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Deltix Round,Spring2021(open for everyone,rated,Div.1+Div.2)相关的知识,希望对你有一定的参考价值。

A. Game of Life

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output

William really likes the cellular automaton called “Game of Life” so he decided to make his own version. For simplicity, William decided to define his cellular automaton on an array containing n cells, with each cell either being alive or dead.

Evolution of the array in William’s cellular automaton occurs iteratively in the following way:

If the element is dead and it has exactly 1 alive neighbor in the current state of the array, then on the next iteration it will become alive. For an element at index i the neighbors would be elements with indices i−1 and i+1. If there is no element at that index, it is considered to be a dead neighbor.
William is a humane person so all alive elements stay alive.
Check the note section for examples of the evolution.

You are given some initial state of all elements and you need to help William find the state of the array after m iterations of evolution.

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

The first line of each test case contains two integers n and m (2≤n≤103,1≤m≤109), which are the total number of cells in the array and the number of iterations.

The second line of each test case contains a string of length n made up of characters “0” and “1” and defines the initial state of the array. “1” means a cell is alive and “0” means it is dead.

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

Output
In each test case output a string of length n, made up of characters “0” and “1” — the state of the array after m iterations of evolution.

Example
inputCopy
4
11 3
01000000001
10 2
0110100101
5 2
10101
3 100
000
outputCopy
11111001111
1110111101
10101
000
Note
Sequence of iterations of evolution for the first test case

01000000001 — initial state
11100000011 — first iteration of evolution
11110000111 — second iteration of evolution
11111001111 — third iteration of evolution
Sequence of iterations of evolution for the second test case

0110100101 — initial state
1110111101 — first iteration of evolution
1110111101 — second iteration of evolution

题解:
扫一遍,每遇到一个1,便向两边的0都维护从这出发使0变为1的最小时间。
然后再判断是否出现101的情况使得中间的0变不了1,既是一个0变成1的最短时间分别比左右两边都大1。
这题注意如何输入。

code

#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <queue>
#include <list>
#include <stack>

using namespace std;

int T;

void ready()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>T;
}

const int oo=1000000009;
int n,m;
string c;
int a[1005];
void work()
{
	cin>>n>>m;
	cin>>c;
	for(int i=n;i>=1;i--)
	  c[i]=c[i-1];
	c[0]='0';
	c[n+1]='0';
	//getchar();
	c[0]='0';
	c[n+1]='0';
	for(int i=1;i<=n;i++)
	  a[i]=oo;
	for(int i=1;i<=n;i++)
	{
		if(c[i]=='0')
		  continue;
		if(c[i]=='1')
		{
			int cnt=0;
			if(c[i-1]=='0')
			for(int j=i-1;j>=1;j--)
			{
				if(c[j-1]=='1')
				  break;
				a[j]=min(++cnt,a[j]);
			}
			cnt=0;
			if(c[i+1]=='0')
			for(int j=i+1;j<=n;j++)
			{
				if(c[j+1]=='1')
				  break;
				a[j]=min(++cnt,a[j]);
			}
		}
	}
	for(int i=2;i<n;i++)
	  if(a[i-1]==a[i+1] && a[i]!=oo)
	    a[i]=oo-1;
	for(int i=1;i<=n;i++)
	{
		if(c[i]=='1')
		  cout<<1;
		else
		{
			if(a[i]<=m)
			  cout<<1;
			else
			  cout<<0;
		}
	}
	cout<<'\\n';
}

int main()
{
    ready();
    while(T--)
      work();
     return 0;
}


B. Lord of the Values

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output

While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a1,a2,…,an to −a1,−a2,…,−an. For some unknown reason, the number of service variables is always an even number.

William understands that with his every action he attracts more and more attention from the exchange’s security team, so the number of his actions must not exceed 5000 and after every operation no variable can have an absolute value greater than 1018. William can perform actions of two types for two chosen variables with indices i and j, where i<j:

Perform assignment ai=ai+aj
Perform assignment aj=aj−ai
William wants you to develop a strategy that will get all the internal variables to the desired values.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤20). Description of the test cases follows.

The first line of each test case contains a single even integer n (2≤n≤103), which is the number of internal variables.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109), which are initial values of internal variables.

Output
For each test case print the answer in the following format:

The first line of output must contain the total number of actions k, which the strategy will perform. Note that you do not have to minimize k. The inequality k≤5000 must be satisfied.

Each of the next k lines must contain actions formatted as “type i j”, where “type” is equal to “1” if the strategy needs to perform an assignment of the first type and “2” if the strategy needs to perform an assignment of the second type. Note that i<j should hold.

We can show that an answer always exists.

Example
inputCopy
2
4
1 1 1 1
4
4 3 1 2
outputCopy
8
2 1 2
2 1 2
2 1 3
2 1 3
2 1 4
2 1 4
1 1 2
1 1 2
8
2 1 4
1 2 4
1 2 4
1 2 4
1 3 4
1 1 2
1 1 2
1 1 4
Note
For the first sample test case one possible sequence of operations is as follows:

“2 1 2”. Values of variables after performing the operation: [1, 0, 1, 1]
“2 1 2”. Values of variables after performing the operation: [1, -1, 1, 1]
“2 1 3”. Values of variables after performing the operation: [1, -1, 0, 1]
“2 1 3”. Values of variables after performing the operation: [1, -1, -1, 1]
“2 1 4”. Values of variables after performing the operation: [1, -1, -1, 0]
“2 1 4”. Values of variables after performing the operation: [1, -1, -1, -1]
“1 1 2”. Values of variables after performing the operation: [0, -1, -1, -1]
“1 1 2”. Values of variables after performing the operation: [-1, -1, -1, -1]
For the second sample test case one possible sequence of operations is as follows:

“2 1 4”. Values of variables after performing the operation: [4, 3, 1, -2]
“1 2 4”. Values of variables after performing the operation: [4, 1, 1, -2]
“1 2 4”. Values of variables after performing the operation: [4, -1, 1, -2]
“1 2 4”. Values of variables after performing the operation: [4, -3, 1, -2]
“1 3 4”. Values of variables after performing the operation: [4, -3, -1, -2]
“1 1 2”. Values of variables after performing the operation: [1, -3, -1, -2]
“1 1 2”. Values of variables after performing the operation: [-2, -3, -1, -2]
“1 1 4”. Values of variables after performing the operation: [-4, -3, -1, -2]

题解:

假设两个数为a和b

变化ab
2ab-a
1bb-a
2b-a
1b-a-a
2b-a-b
1-a-b

相邻两个数,经过6次变换便能相互变成相反数。

code

#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <queue>
#include <list>
#include <stack>

using namespace std;

int T;

void ready()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>T;
}

const int oo=1000000009;
int n,m;
int d;
int ans[1005];

void work()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
	 } 
	cout<<3*n<<'\\n';
	for(int i=1;i<=n;i+=2)
	{
		cout<<2<<' '<<i<<' '<<i+1<<'\\n';
		cout<<1<<' '<<i<<' '<<i+1<<'\\n';
		cout<<2<<' '<<i<<' '<<i+1<<'\\n';
		cout<<1<<' '<<i<<' '<<i+1<<'\\n';
		cout<<2<<' '<<i<<' '<<i+1<<'\\n';
		cout<<1<<' '<<i<<' '<<i+1<<'\\n';
	}
}

int main()
{
    ready();
    while(T--)
      work();
     return 0;
}

C. Compression and Expansion

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output

William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.

A valid nested list is any list which can be created from a list with one item “1” by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items a1.a2.a3.⋯.ak and can be one of two types:

Add an item a1.a2.a3.⋯.ak.1 (starting a list of a deeper level), or
Add an item a1.a2.a3.⋯.(ak+1) (continuing the current level).
Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the “Notes” section.
When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the “Ctrl-S” he wanted to hit. It’s not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number.

William wants you to help him restore a fitting original nested list.

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

The first line of each test case contains a single integer n (1≤n≤103), which is the number of lines in the list.

Each of the next n lines contains a single integer ai (1≤ai≤n), which is what remains of William’s nested list.

It is guaranteed that in each test case at least one fitting list exists.

It is guaranteed that the sum of values n across all test cases does not exceed 103.

Output
For each test case output n lines which represent a valid nested list, which could become the data provided to you by William.

If there are multiple answers, print any.

Example
inputCopy
2
4
1
1
2
3
9
1
1
1
2
2
1
2
1
2
outputCopy
1
1.1
1.2
1.3
1
1.1
1.1.1
1.1.2
1.2
1.2.1
2
2.1
2.2
Note
In the second example test case one example of a fitting list is:

1

1.1

1.1.1

1.1.2

1.2

1.2.1

2

2.1

2.2

This list can be produced by using the sequence of operations shown below:
Original list with a single item 1.
Insert item 2 by using the insertion operation of the second type after item 1.
Insert item 1.1 by using the insertion operation of the first type after item 1.
Insert item 1.2 by using the insertion operation of the second type after item 1.1.
Insert item 1.1.1 by using the insertion operation of the first type after item 1.1.
Insert item 1.1.2 by using the insertion operation of the second type after item 1.1.1.
Insert item 1.2.1 by using the insertion operation of the first type after item 1.2.
Insert item 2.1 by using the insertion operation of the first type after item 2.
Insert item 2.2 by using the insertion operation of the second type after item 2.1.

题解
模拟题,即模拟书目名单。答案不唯一。

code

#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <cstring>
#include <vector>
#include <queue>
#include <list>
#include <stack>

using namespace std;

int T;

void ready()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>T;
}

const int oo=1000000009;
int n,m;
int d;
int ans[1005];

void work()
{
	memset(ans,0,sizeof(ans));
	d=0;
	cin>>n;
	while(n--)
	{
		int x;
		cin>>x;
		if(x==1)
		{
			ans[++d]=1;
		}
		else
		{
			if(ans[d]==x-1)
			{
				ans[d]=x;
			}
			else
			{
				
				while(ans[d]!=x-1)
			  	  d--;
				ans[d]=x;
			}
			
		}
		for(int i=1;i<=d;i++)
		{
			if(i!=1)
			  cout<<'.';
			cout<<ans[i];
		}
		cout<<'\\n';
	}
}

int main()
{
    ready();
    while(T--)
      work();
     return 0;
}

以上是关于Deltix Round,Spring2021(open for everyone,rated,Div.1+Div.2)的主要内容,如果未能解决你的问题,请参考以下文章

Deltix Round,Spring2021(open for everyone,rated,Div.1+Div.2)

Deltix Round, Spring 2021 (rated, Div. 1 + Div. 2)ABCDEFGH题解

Deltix Round, Spring 2021 (open for everyone, rated, Div. 1 + Div. 2) A~D题解

Deltix Round, Summer 2021 (open for everyone, rated, Div. 1 + Div. 2)

Deltix Round, Summer 2021 Div. 1 + Div. 2 A B C D

Deltix Round, Summer 2021 Div. 1 + Div. 2 A B C D