链接

对于组合数学是一点也不了解

讲解

重要一点 要知道一个循环里最少的交换次数是m-1次 、

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define N 10010
#define INF 0xfffffff
int a[N],b[N],po[N*],vis[N*];
int main()
{
int i,n;
while(scanf("%d",&n)!=EOF)
{
memset(vis,,sizeof(vis));
for(i = ; i <= n ;i++)
{
scanf("%d",&a[i]);
b[i] = a[i];
}
sort(b+,b+n+);
for(i = ; i <= n ; i++)
po[b[i]] = i;
int ans=;
for(i = ; i <= n ; i++)
{
if(!vis[a[i]])
{
int sum = a[i],minz = INF ,o = a[i],t=;
while()
{
vis[o] = ;
t++;
minz = min(minz,o);
int k = po[o];
o = a[k];
if(vis[o])
break;
sum+=o;
}
ans +=min(sum-minz+minz*(t-),sum+minz+b[]*(t+));
}
}
printf("%d\n",ans);
}
return ;
}

poj3270Cow Sorting(置换)的更多相关文章

  1. poj3270Cow Sorting(置换+贪心)

    Cow Sorting Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7587   Accepted: 2982 Descr ...

  2. poj 3270 Cow Sorting (置换入门)

    题意:给你一个无序数列,让你两两交换将其排成一个非递减的序列,每次交换的花费交换的两个数之和,问你最小的花费 思路:首先了解一下什么是置换,置换即定义S = {1,...,n}到其自身的一个双射函数f ...

  3. Cow Sorting(置换)

    http://poj.org/problem?id=3270 // File Name: poj3270.cpp // Author: bo_jwolf // Created Time: 2013年1 ...

  4. bzoj 1119 [POI2009]SLO && bzoj 1697 [Usaco2007 Feb]Cow Sorting牛排序——思路(置换)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1119 https://www.lydsy.com/JudgeOnline/problem.p ...

  5. [BZOJ1697][USACO2007 FEB]Cow Sorting牛排序:贪心+置换

    分析 一个月前做的一道题补一下题解,就简单写一写吧. 单独考虑每一个循环节,如果只进行内部的调整,最优方案显然是把最小的绕这个循环交换一圈. 但是借助全局最小值可能使答案更优,两种情况取个\(\max ...

  6. BZOJ 1697: [Usaco2007 Feb]Cow Sorting牛排序(置换+贪心)

    题面 Description 农夫JOHN准备把他的 N(1 <= N <= 10,000)头牛排队以便于行动.因为脾气大的牛有可能会捣乱,JOHN想把牛按脾气的大小排序.每一头牛的脾气都 ...

  7. Cow Sorting(置换群)

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

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

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

  9. 【UVA 11077】 Find the Permutations (置换+第一类斯特林数)

    Find the Permutations Sorting is one of the most used operations in real life, where Computer Scienc ...

随机推荐

  1. JavaScript null and undefined

    http://stackoverflow.com/questions/6429225/javascript-null-or-undefined var x; x == null // true x = ...

  2. html5画四边形

    <canvas id='test02'></canvas> <script> var canvas = document.getElementById('test0 ...

  3. Oracle 动态视图1 V$LOCK

    v$lock显示数据库当前持有锁情况 Column Datatype Description SID NUMBER 会话ID TYPE VARCHAR2(2) 表示锁的类型.值包括TM,TX,等 ID ...

  4. Head of a Gang (map+邻接表+DFS)

    One way that the police finds the head of a gang is to check people's phone calls. If there is a pho ...

  5. [转载]iOS本地推送-备用

    第一步:创建本地推送// 创建一个本地推送UILocalNotification *notification = [[[UILocalNotification alloc] init] autorel ...

  6. 1191: [HNOI2006]超级英雄Hero - BZOJ

    Description 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金.主持人问题准备了若干道题目,只有当选手正确回 ...

  7. js检测对象的类型

    在JavaScript中,想要判断某个对象值属于哪种内置类型,最靠谱的做法就是通过Object.prototype.toString方法. 示例: var array=[1,2,3]; Object. ...

  8. 全面学习cookies

    来自<javascript高级程序设计 第三版:作者Nicholas C. Zakas>的学习笔记(五) 本来想自己总结的,但是某文总结太好了(http://www.cnblogs.com ...

  9. [转载]js 遍历数组对象

    有一个JSON数组如下 all = {"error":0,"content":[{"name":"北京","v ...

  10. 1058-Tom and Jerry

    描述 Tom和Jerry在10*10的方格中: *...*..... ......*... ...*...*.. .......... ...*.C.... *.....*... ...*...... ...