列表

详情


NC216212. No114514

描述

found too much "" in this problem set. As a years old student, he can't stand it anymore. So he invites you to help him clean up the problem set.
                      
has a sequence consists of numbers, the indices label from to . Each number A_i in the sequence can only be or or . He does not want six consecutive numbers in the sequence , so he invites you to perform some operations on the sequence. In one operation, you can select an integer and change A_i to B_i, B_i can only be or or . Your task is to make the sequence do not contains the six consecutive numbers in at most  (rounding down) operations.
You are not required to minimize the number of operations.

输入描述

The first line of the input contains an integer , denoting the length of the sequence.
The second line of the input contains Integers A_i, it's guaranteed that .

输出描述

You should print  numbers in one line, denoting the sequence  after your operations.
We have proof that a solution always exists. If there are multiple solutions, print any.
End-of-line spaces are allowed in this problem. You can output with or without end-of-line spaces.

示例1

输入:

7
1 1 1 4 5 1 4

输出:

1 4 1 4 5 1 4

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C(clang11) 解法, 执行用时: 36ms, 内存消耗: 1532K, 提交时间: 2020-12-26 15:12:17

#include<stdio.h>
main()
{
	int n;
	scanf("%d",&n);
	int a[n];int i;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<=n-6;i++)
	{
		if(a[i]==1&&a[i+1]==1&&a[i+2]==4&&a[i+3]==5&&a[i+4]==1&&a[i+5]==4) a[i+2]=5;
	}
	for(i=0;i<n;i++)
	{
		printf("%d ",a[i]);
	}
}

C++(clang++ 11.0.1) 解法, 执行用时: 429ms, 内存消耗: 1612K, 提交时间: 2023-08-05 14:15:12

#include<iostream>
using namespace std;
const int N=2e5+5;
int a[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i>=6&&a[i]==4&&a[i-1]==1&&a[i-2]==5&&a[i-3]==4&&a[i-4]==1&&a[i-5]==1)a[i]=5;
		cout<<a[i]<<" ";
	}
}

Python3(3.9) 解法, 执行用时: 106ms, 内存消耗: 6024K, 提交时间: 2020-12-26 15:26:05

n,s=input(),''.join(e for e in input().split())
t = s.find('114514')
for e in s.replace('114514','111514'):
    print(e,end=' ')
    

上一题