http://acm.upc.edu.cn/problem.php?id=2959

这就是个水题,之所以要写这个题是感觉很有纪念意义

用力看就是盲……
23333333333333333

这个题就是最小交换几次使数组有序,首先想到的竟然是逆序数

但是逆序数是冒泡排序用的,怎么可能最小……!!!!

具体题解是:

先用结构体标记每个元素的位置和内容,然后进行排序

跟原来的数组进行比较,位置不符合,将原数组 元素 跟 本该排好序在这个位置的元素交换

然后 二分查找 结构体数组里面 该 元素 将 坐标更新

就是这样,很无聊……

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <vector> const int MAXN = + ;
const double ESP = 10e-;
const double Pi = atan(1.0) * ;
const int INF = 0x7fffffff;
const int MOD = ;
typedef long long LL; LL gcd(LL a,LL b){
return b ?gcd(b,a%b): a;
}
using namespace std;
struct P{
int x;
int pp;
bool operator < (const P a)const{
return x < a.x;
}
};
int a[MAXN];
P b[MAXN];
int main(){
// freopen("input.txt","r",stdin);
int n;
while(~scanf("%d",&n)){
for(int i = ;i < n;i++){
scanf("%d",&a[i]);
b[i].x = a[i];
b[i].pp = i;
}
sort(b,b+n);
int ans = ;
for(int i = ;i < n;i++){
if(a[i] != b[i].x){
int pp = b[i].pp;
int tmp = a[i];
a[i] = b[i].x;
a[pp] = tmp;
P xx;
xx.x = tmp;
int x = lower_bound(b,b+n,xx) - b;
b[x].pp = pp;
ans++;
}
}
printf("%d\n",ans);
}
return ;
}

UPC 2959: Caoshen like math 这就是个水题的更多相关文章

  1. POJ2485Highways(prime 水题)

    Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26516   Accepted: 12136 Descri ...

  2. hdu 2393:Higher Math(计算几何,水题)

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

  3. upc组队赛14 Bus stop【签到水】

    Bus Stop 题目描述 In a rural village in Thailand, there is a long, straight, road with houses scattered ...

  4. hdu1240 bfs 水题

    原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...

  5. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  6. fzuoj Problem 2182 水题

    http://acm.fzu.edu.cn/problem.php?pid=2182 Problem 2182 水题 Accept: 188    Submit: 277Time Limit: 100 ...

  7. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  8. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  9. Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题

    A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

随机推荐

  1. sql中select语句的逻辑执行顺序

    下面是SELECT语句的逻辑执行顺序: FROMONJOINWHEREGROUP BYWITH CUBE or WITH ROLLUPHAVINGSELECTDISTINCTORDER BYTOP M ...

  2. iOS开发之SDWebImage详解

    介绍 github地址: https://github.com/rs/SDWebImage 简介 一个异步图片下载及缓存的库 特性: 一个扩展UIImageView分类的库,支持加载网络图片并缓存图片 ...

  3. Mac编程(QT有许多专门的资料)

    Mac OS X 上在应用运行时,在Dock上的图标右键会有额外的菜单部分.参考iTunes运行时右键的菜单.使用Qt在Mac下的一个set_menu(QMenu *)函数实现,文档里有写 http: ...

  4. BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场

    题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 491  S ...

  5. 【转】2014区域赛小结(牡丹江&&鞍山)by kuangbin

    Posted on 2014年10月20日 by kuangbin 最后的两场区域赛结束了! ICPC生涯的最后两场区域赛,选择了前两个赛区——牡丹江和鞍山,主要是时间比较靠前,而且我向来对东北赛区有 ...

  6. caffe神经网络框架的辅助工具(将图片转换为leveldb格式)

    caffe中负责整个网络输入的datalayer是从leveldb里读取数据的,是一个google实现的很高效的kv数据库. 因此我们训练网络必须先把数据转成leveldb的格式. 这里我实现的是把一 ...

  7. BZOJ 1060: [ZJOI2007]时态同步( 树形dp )

    坑爹...数据是错的..详见discuss  http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=1060 先求根到叶子的距离最大值x, 然后把所有叶 ...

  8. Android 中 ListView 常用属性合集

    class ListView.FixedViewInfo//用来在列表内展现一个固定位置视图,如在列表顶端的header和在列表底端的footer 一.XML属性 1.ListView的XML属性 a ...

  9. 网络编程TCP协议-聊天室

    网络编程TCP协议-聊天室(客户端与服务端的交互); <span style="font-size:18px;">1.客户端发数据到服务端.</span> ...

  10. php 登陆动作详解

    <?php class LoginAction extends Action { function index(){ $this->display(); } function do_log ...