codeforces A. Slightly Decreasing Permutations 题解

Permutation p is
an ordered set of integers p1,??p2,??...,??pn,
consisting of n distinct positive integers, each of them doesn‘t exceed n.
We‘ll denote the i-th element of permutation p as pi.
We‘ll call number n the size or the length of permutation p1,??p2,??...,??pn.

The decreasing coefficient of permutation p1,?p2,?...,?pn is
the number of such i (1?≤?i?<?n), that pi?>?pi?+?1.

You have numbers n and k.
Your task is to print the permutation of length n with decreasing coefficient k.

Input

The single line contains two space-separated integers: n,?k (1?≤?n?≤?105,?0?≤?k?<?n) —
the permutation length and the decreasing coefficient.

Output

In a single line print n space-separated integers: p1,?p2,?...,?pn —
the permutation of length n with decreasing coefficient k.

If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.

Sample test(s)

input

5 2

output

1 5 2 4 3

这种题目难就难在下标处理。当然题目本身不难。

void SlightlyDecreasingPermutations()
{
	int n, k;
	cin>>n>>k;
	int *A = new int[n];

	for (int i = 0; i < n - k - 1; i++)
	{
		A[i] = i + 1;
	}
	for (int i = n - k - 1, j = n; i < n; i++, j--)
	{
		A[i] = j;
	}
	for (int i = 0; i < n; i++)
	{
		cout<<A[i]<<‘ ‘;
	}
	delete [] A;
}
void SlightlyDecreasingPermutations_2()
{
	int n, k;
	cin>>n>>k;
	int *A = new int[n];

	for(int i = 0; i < n; ++i) A[i] = i+1;
	reverse(A,A+k+1);

	for(int i = 0; i < n; ++i) cout<<A[i]<<‘ ‘;
}

codeforces A. Slightly Decreasing Permutations 题解,码迷,mamicode.com

时间: 2024-10-26 18:18:51

codeforces A. Slightly Decreasing Permutations 题解的相关文章

Codeforces Round #177 (Div. 2) 题解

[前言]咦?现在怎么流行打CF了?于是当一帮大爷在执着的打div 1的时候,我偷偷的在刷div 2.至于怎么决定场次嘛,一般我报一个数字A,随便再拉一个人选一个数字B.然后开始做第A^B场.如果觉得机密性不高,来点取模吧.然后今天做的这场少有的AK了.(其实模拟赛只做完了4题,最后1题来不及打了) 等等,话说前面几题不用写题解了?算了,让我难得风光一下啦. [A] A. Polo the Penguin and Segments time limit per test 2 seconds mem

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F 1296A - Array with Odd Sum 思路: 如果一开始数组的sum和是奇数,那么直接YES, 否则:如果存在一个奇数和一个偶数,答案为YES,否则为NO 代码: int n; int a[maxn]; int main() { //freopen("D:\\code\\text\\input.txt","r",stdin); //freopen(

Codeforces A. Valera and X 题解

判断二维字符串是否满足下面条件: on both diagonals of the square paper all letters are the same; all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the progra

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

codeforces A. Shaass and Oskols 题解

Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delici

Codeforces Round #FF (Div. 2) 题解

比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n 

Codeforces D. Giving Awards 412 题解

就是按照一定顺序输出排序. 比如a欠b的钱就不能先输出a然后输出b. 本题的技巧就是,要求的是不能先输出a然后输出b,但是可以先输出b然后输出a. 故此可以按照a欠b的钱的关系,建立图,然后DFS深度优先搜索,然后逆向记录点,输出这些逆向点,也就是a欠b的钱,就先输出b然后输出a,那么这个顺序就满足要求了. 很狡猾的题意.要细心.不然就搞半天都白搞了. 题目连接:http://codeforces.com/problemset/problem/412/D #include <stdio.h>

Codeforces Round #259 (Div. 2) 题解

A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n?>?1) is an n?×?n 

codechef Little Elephant and Permutations题解

The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numbers 1, 2, ...,N. He calls a permutation A good, if the number of its inversions is equal to the number of its local inversions. The number of inversio