Valera and Swaps】的更多相关文章

A permutation p of length n is a sequence of distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). A permutation is an identity permutation, if for any i the following equation holds pi = i. A swap (i, j) is the operation that swaps elements pi and pj in t…
题意: 给定一个1~n的排列(n<=3000),输出字典序最小且次数最少的交换操作,使得操作后的排列可以通过最少m次交换得到排列[1,2,...n] Solution: 可以将排列的对应关系看做边,f[i]=i,代表自环.那么根据置换原理,图中有k个环,则需要最少n-k次交换操作得到排列[1,2...n].所以,先找出图中的环,对同一个环的位置进行标记.这样对不在同一个环的两个位置进行交换,会将两个环合并.将在同一个环内的两个位置进行交换,会将这个环分成两个环. 只需要,判断需要加环还是去环.贪…
题意:1-n的一个排列, p2, ..., pn,f(p)的定义是此排列要交换最少的数对能够回到原排列1,2,3,4...n.给一个排列p.要将其变换成f值为m的排列,问至少要交换几个数对,并输出字典序最小的那组答案. 解法:处理出全部的置换群,求出环数k,此时f值为n-k.然后推断n-k和m的大小,分为两种操作 1.加环,这个是在随意元素个数大于1的环内交换随意两个数都能够做到加环 2.减环,交换随意两个环的随意两个元素.就能够做到将两个环连接起来 题目要求是输出字典序最小,那么就暴力搞. 代…
题意: 定义 $f(p)$ 表示将 $p$ 序列变换为有序序列最少要交换多少次,给一 $1 \sim n$ 的排列 $a$ ,给一整数 $m$, 求问将 $a$ 最少交换多少次能得到 $p$ ,使得 $f(p) = m$,并将以此交换视作一个两个数字,将交换按顺序排列开 求出字典序最小的交换序列. 解法: 记 $id$ 表示排列 $id(i) = i$ 考虑 $f(p)$ 怎么求,可以发现,将原排列视作一个从$p$置换到$id$的置换,则将置换拆分成 $tot$ 个循环后, 最小交换次数就是$\…
layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces - 群论 --- 传送门 A.Valera and Antique Items (签到) 题意 如果当前钱数比一组数中最小的还要大就+1 思路 直接模拟 #include<bits/stdc++.h> using namespace std…
[codeforces 339]E. Three Swaps 试题描述 Xenia the horse breeder has n (n > 1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row looks as foll…
C. Valera and Elections   The city Valera lives in is going to hold elections to the city Parliament. The city has n districts and n - 1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's…
Mapping the Swaps Sorting an array can be done by swapping certain pairs of adjacent entries in the array. This is the fundamental technique used in the well-known bubble sort. If we list the identities of the pairs to be swapped, in the sequence the…
题目例如以下: Mapping the Swaps  Sorting an array can be done by swapping certain pairs of adjacent entriesin the array. This is the fundamental technique used in the well-knownbubble sort. If we list the identities of the pairs to be swapped, in thesequen…
A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn…