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

题解看这个吧,我就不写了: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. zoj2001 Adding Reversed Numbers

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2001 Adding Reversed Numbers Time ...

  2. [device tree] How to decompile a compiled .dtb (device tree blog) into .dts (device tree source).

    $ ./out/target/product/project_name/obj/KERNEL_OBJ/scripts/dtc/dtc -I dtb -O dts -o decompiled.dts ~ ...

  3. rtems-os-source

    http://blog.csdn.net/xpx3216/article/details/5776941 http://tech.hqew.com/fangan_421204 https://gith ...

  4. 【bzoj4567】SCOI2016背单词

    题号莫名喜感. 倒序建Trie,dfs这棵Trie,贪心一下,每次按照size排序计算贡献就好. #include<bits/stdc++.h> #define N 100010 #def ...

  5. SVN--版本控制系统

    引言 SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS.互联网上很多版本控制服务已从CVS迁移到Subvers ...

  6. 阿里CDN核心技术解密

    1. 阿里CDN组件分层 其中应用层主要用到的技术有负载均衡和缓存, 负载均衡包括全局负载均衡和本地负载均衡; 缓存通过HTTP缓存服务器Swift做HTTP缓存. 全局负载均衡以DNS服务器Phar ...

  7. Github精选 – 适合移动端的HTML5 Datepicker

     2016-01-12 (updated: 2017-01-07) 15731 通过 HTML5 的 <input> 新属性可以简单方便地调用手机的原生 Datepicker,但功能较弱, ...

  8. spring使用aop需要的jar包,和常见异常

    3.0以后spring不再一起发布aop依赖包,需要自己导入: 必须包: 这几个jar包分别为 1.org.springframework.aop-3.1.1.RELEASE  这个是spring的 ...

  9. Centos7 环境准备

    Centos7 环境准备 #关闭防火墙 systemctl stop firewalld systemctl disable firewalld #关闭selinux sed -i 's/SELINU ...

  10. MySQL关键字大全

    转载自:https://blog.csdn.net/benxiaohai888/article/details/77803090 在使用MySQL的时候,一般尽量避免用关键字作为表名,如使用关键字做表 ...