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. S2S:分享出的营销机遇

    (速途网专栏 作者:高学争)经常在网上购物的你,有没有遇到过这样的问题:你知道自己想买什么,但是在淘宝上一搜,出来了数以万计的同类型,他们有着同样的价位(甚至可能是同样的图片),但是由不同的商家提供, ...

  2. asp.net 开发注意的几点

    WIN7中组件服务中的DCOM配置找不到Microsoft Excel应用程序的解决办法: 这主要是64位系统的问题,excel是32位的组件,所以在正常的系统组件服务里是看不到的 可以通过在运行里面 ...

  3. zepto API参考(~~比较全面)

    Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jquery有着类似的api. 如果你会用jquery,那么你也会用zepto. 设计的目的是提供jquery的类似的APIs ...

  4. TCP/IP之三次握手、四次挥手

    参照:http://www.cnblogs.com/hnrainll/archive/2011/10/14/2212415.html 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建 ...

  5. CentOS下配置多个Tomcat同时运行 本篇文章来源于 Linux公社网站(www.linuxidc.com)

    原文地址:http://blog.csdn.net/tjcyjd/article/details/46553361 版权声明:本文为博主原创文章,未经博主允许不得转载. 同一服务器部署多个tomcat ...

  6. 我的cocos2d-x集成sharesdk之旅(转)

    链接地址:http://blog.csdn.net/yeungxuguang/article/details/18227153 本文出自:http://www.iteye.com/topic/1130 ...

  7. input file 在开发中遇到的问题 类似ajax form表单提交 input file中的文件

    最近在做项目的过程中遇到个问题,在这里做个记录防止日后忘记 现今的主流浏览器由于ajax提交form表单无法把文件类型数据提交到后台,供后台处理,可是开发中由于某些原因又不得不用ajax提交文件, 为 ...

  8. shell的wc命令统计 head tail命令详解

    Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 1.命令格式: wc [选项]文件... 2.命令功能: 统计指定文件中的字节数. ...

  9. excel unixtime与北京时间互转

    unixtime转北京时间,在单元格内输入:=INT((B2-70*365-19)*86400-8*3600)   *.要设置一下单元格格式为y-m-d h:m:s才会正确显示 北京时间转unixti ...

  10. php language construct 语言构造器

    isset和empty看起来像是函数,我们也经常把它当作函数一样使用,但是实际上,它们是语言构造器. php中的语言构造器就相当于C中的预定义宏的意思,它属于php语言内部定义的关键词,不可以被修改, ...