并不应该叫置换群……只是用到了置换而已,并没有群。

题解看这个吧,我就不写了:http://www.cnblogs.com/kuangbin/archive/2012/09/03/2669013.html

证明的话可以自己手撸几组数据模拟一下,比较容易。

复杂度O(n)。

算是个经典题吧?

#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define INF 2147483647
vector<int>vs[10010];
struct data{
int p,v;
}t[10010];
bool cmp(const data &a,const data &b){
return a.v<b.v;
}
int n,e,ma[10010],minn=INF,ans,t1,t2,minx;
bool vis[10010];
int a[10010];
void dfs(int U){
vis[U]=1;
minx=min(minx,ma[U]);
if(!vis[a[U]]){
dfs(a[U]);
}
t1+=(minx+ma[U]);
t2+=(minn+ma[U]);
}
int main(){
// freopen("poj3270.in","r",stdin);
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&t[i].v);
t[i].p=i;
minn=min(t[i].v,minn);
}
sort(t+1,t+n+1,cmp);
for(int i=1;i<=n;++i){
if(t[i].v!=t[i-1].v){
++e;
}
a[e]=t[i].p;
ma[e]=t[i].v;
}
for(int i=1;i<=n;++i){
if(!vis[a[i]]){
t1=t2=0;
minx=INF;
dfs(a[i]);
t1-=(minx+minx);
t2+=(minx+minn);
ans+=min(t1,t2);
}
}
printf("%d\n",ans);
return 0;
}

【置换群】poj3270 Cow Sorting的更多相关文章

  1. poj3270 Cow Sorting

    给定有序数组a[1...n]的一个置换a[σ(1)...σ(n)], 通过交换数组元素把置换后的数组恢复为有序, 定义进行一次交换的代价为两元素之和,试问此过程的最小总代价. 实际上一种置换即定义S ...

  2. Cow Sorting(置换群)

    Cow Sorting Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6664   Accepted: 2602 Descr ...

  3. HDU Cow Sorting (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1  ...

  4. BZOJ1697: [Usaco2007 Feb]Cow Sorting牛排序

    1697: [Usaco2007 Feb]Cow Sorting牛排序 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 387  Solved: 215[S ...

  5. hdu 2838 Cow Sorting(树状数组)

    Cow Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. Cow Sorting hdu 2838

    Cow Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. BZOJ_1697_[Usaco2007 Feb]Cow Sorting牛排序_贪心

    BZOJ_1697_[Usaco2007 Feb]Cow Sorting牛排序_贪心 Description 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行 ...

  8. 树状数组 || 线段树 || Luogu P5200 [USACO19JAN]Sleepy Cow Sorting

    题面:P5200 [USACO19JAN]Sleepy Cow Sorting 题解: 最小操作次数(记为k)即为将序列倒着找第一个P[i]>P[i+1]的下标,然后将序列分成三部分:前缀部分( ...

  9. 【BZOJ 1697】1697: [Usaco2007 Feb]Cow Sorting牛排序

    1697: [Usaco2007 Feb]Cow Sorting牛排序 Description 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行动.因为脾气大 ...

随机推荐

  1. Angular2.0 基础: 环境搭建

    最近在学习Angular2的使用,其实看过Angular2 文档的都知道,相比于之前的Angular1,Angular2 的改动还是挺大的. 而对于‘angular2 的本地开发环境的搭建的中,我们首 ...

  2. 双内网渗透代理之reGeorg+Proxifier

    由于这个工具第一次体验感觉还不错,很稳定.因此在这记录一下reGeorg+Proxifier的配置及其使用. 下载地址 :https://github.com/sensepost/reGeorg.gi ...

  3. [Leetcode Week13]Search a 2D Matrix

    Search a 2D Matrix 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/search-a-2d-matrix/description/ D ...

  4. 通过编译函数库来学习GCC【转】

    转自:http://blog.csdn.net/u012365926/article/details/51446295 基本概念 什么是库 在windows平台和linux平台下都大量存在着库. 本质 ...

  5. device tree property ---- interrupt-names

    device tree source 的 interrupt-names property 會對應到 pltform_get_irq_byname() 的第二個參數. .dtsi or .dts in ...

  6. python基础===时间处理模块

    时间模块 Python中有很多方便我们处理时间信息的模块 time 模块 datetime 模块 pytz 模块 dateutil 模块 这里我们着重介绍的是前两种 time模块 time.time( ...

  7. 在linux内核中获得比jiffies精度更高的时间值【转】

    转自:http://blog.chinaunix.net/uid-20672257-id-2831219.html 内核一般通过jiffies值来获取当前时间.尽管该数值表示的是自上次系统启动到当前的 ...

  8. request.getRemoteAddr() 获取的值为0:0:0:0:0:0:0:1的原因及解决办法

    问题: 在近期开发的javaweb项目中,需要记录登录时的电脑ip地址和主机名,通过request.getRemoteAddr()和request.getRemoteHost()得到的值都是0:0:0 ...

  9. Excel Sheet Column Title&&Excel Sheet Column Number

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  10. PHP需要学习成长路径

    第一阶段:基础阶段(基础PHP程序员) 重点:把LNMP搞熟练(核心是安装配置基本操作) 目标:能够完成基本的LNMP系统安装,简单配置维护;能够做基本的简单系统的PHP开发;能够在PHP中型系统中支 ...