diff options
author | Jack Sangdahl <[email protected]> | 2024-12-19 20:32:07 -0700 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2024-12-19 20:32:07 -0700 |
commit | 700f2303dfa3307117e8106215c146c419f426cc (patch) | |
tree | d3d767473ba25b197ebb22dd6168dd322a32bb32 | |
parent | c922967b8b2ce6ec78effbc54ae0700c7af1e875 (diff) | |
download | cses-master.tar.gz cses-master.zip |
-rw-r--r-- | introductory_problems/permutations.cpp | 18 | ||||
-rw-r--r-- | introductory_problems/readme.md | 11 |
2 files changed, 27 insertions, 2 deletions
diff --git a/introductory_problems/permutations.cpp b/introductory_problems/permutations.cpp new file mode 100644 index 0000000..46d8e79 --- /dev/null +++ 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 index cca3339..2c2e44a 100644 --- 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) |