cses

CSES Solutions (0x6A73)
git clone https://git.pngu.org/cses
Log | Files | Refs

commit 700f2303dfa3307117e8106215c146c419f426cc
parent c922967b8b2ce6ec78effbc54ae0700c7af1e875
Author: Jack Sangdahl <jack@pngu.org>
Date:   Thu, 19 Dec 2024 20:32:07 -0700

1070. permutations

Diffstat:
Aintroductory_problems/permutations.cpp | 18++++++++++++++++++
Mintroductory_problems/readme.md | 11+++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/introductory_problems/permutations.cpp b/introductory_problems/permutations.cpp @@ -0,0 +1,18 @@ +// 1070. Permutations +#include <bits/stdc++.h> +using namespace std; + +int main() { + static int num; + scanf("%d", &num); + if (num == 1) + printf("1 "); + else if (num <= 3) + printf("NO SOLUTION\n"); + else { + for (int i = 2; i <= num; i += 2) + printf("%d ", i); + for (int i = 1; i <= num; i += 2) + printf("%d ", i); + } +} diff --git a/introductory_problems/readme.md b/introductory_problems/readme.md @@ -22,8 +22,15 @@ You are given a DNA sequence: a string consisting of A, C, G, and T. Your task i **Output**: Print one integer: the length of the longest repetition. (Example: 3) ### Increasing Array -You are given an array of `n` integers. You want to modify the array so that it is increasing, ie. every element is at least as large as the previous element. On each move, you may increase the value of any elementby one. What is the minimum number of moves required? +You are given an array of `n` integers. You want to modify the array so that it is increasing, ie. every element is at least as large as the previous element. On each move, you may increase the value of any element by one. What is the minimum number of moves required? -**Input**: Thefirst input line contains an integer `n`: the size of the array. Then the second line contains `n` integers: the contents of the array. (Example: 5`\n`3 2 5 1 7) +**Input**: The first input line contains an integer `n`: the size of the array. Then the second line contains `n` integers: the contents of the array. (Example: 5`\n`3 2 5 1 7) **Output**: Print the minimum number of moves. (Example: 5) + +### Permutations +A permutation of integers `1, 2, ..., n` is called beautiful if there are no adjacent elements whose difference is 1. Given `n`, construct a beautiful permutation if such a permutation exists. + +**Input**: The only input line contains an integer `n`. (Example: 5) + +**Output**: Print a beautiful permutation of integers. If there are several solutions, you may print any of them. If there are no solutions, print "NO SOLUTION". (Example: 4 2 5 3 1)