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

变化 a b
2 a b-a
1 b b-a
2 b -a
1 b-a -a
2 b-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;
}

全部评论

相关推荐

最近群里有很多同学找我看简历,问问题,主要就是集中在明年三月份的暑期,我暑期还能进大厂嘛?我接下来该怎么做?对于我来说,我对于双非找实习的一个暴论就是title永远大于业务,你在大厂随随便便做点慢SQL治理加个索引,可能就能影响几千人,在小厂你从零到一搭建的系统可能只有几十个人在使用,量级是不一样的。对双非来说,最难的就是约面,怎么才能被大厂约面试?首先这需要一点运气,另外你也需要好的实习带给你的背书。有很多双非的同学在一些外包小厂待了四五个月,这样的产出有什么用呢?工厂的可视化大屏业务很广泛?产出无疑是重要的,但是得当你的实习公司到了一定的档次之后,比如你想走后端,那么中厂后端和大厂测开的选择,你可以选择中厂后端(注意,这里的中厂也得是一些人都知道的,比如哈啰,得物,b站之类,不是说人数超过500就叫中厂),只有这个时候你再去好好关注你的产出,要不就无脑大厂就完了。很多双非同学的误区就在这里,找到一份实习之后,就认为自己达到了阶段性的任务,根本不再投递简历,也不再提升自己,玩了几个月之后,美其名曰沉淀产出,真正的好产出能有多少呢?而实际上双非同学的第一份实习大部分都是工厂外包和政府外包!根本无产出可写😡😡😡!到了最后才发现晚了,所以对双非同学来说,不要放过任何一个从小到中,从中到大的机会,你得先有好的平台与title之后再考虑你的产出!因为那样你才将将能过了HR初筛!我认识一个双非同学,从浪潮到海康,每一段都呆不久,因为他在不断的投递和提升自己,最后去了美团,这才是双非应该做的,而我相信大部分的双非同学,在找到浪潮的那一刻就再也不会看八股,写算法,也不会打开ssob了,这才是你跟别人的差距。
迷茫的大四🐶:我也这样认为,title永远第一,只有名气大,才有人愿意了解你的简历
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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