UPC 2959: Caoshen like math 这就是个水题
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 这就是个水题的更多相关文章
- POJ2485Highways(prime 水题)
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26516 Accepted: 12136 Descri ...
- hdu 2393:Higher Math(计算几何,水题)
Higher Math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- upc组队赛14 Bus stop【签到水】
Bus Stop 题目描述 In a rural village in Thailand, there is a long, straight, road with houses scattered ...
- hdu1240 bfs 水题
原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- fzuoj Problem 2182 水题
http://acm.fzu.edu.cn/problem.php?pid=2182 Problem 2182 水题 Accept: 188 Submit: 277Time Limit: 100 ...
- 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 ...
- 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 ...
- 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/ ...
随机推荐
- IE11中[if lt IE 9]兼容性问题
IE11不支持<!--[if lt IE 9]> <![endif]--> ,蛋疼的IE!!!
- file.encoding到底指的是什么呢?
转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50918506 <Java利用System.getProperty(“file. ...
- STL front() ,back()和begin(),end()区别
首先看看vector里面的: reference front(); const_reference front() const; queue里面的: value_type& front(); ...
- java学习之IO字符流
package com.io; import java.io.*; /** * 文件字符流的读取 * @author ganhang * */ public class FileReaderDemo ...
- (Problem 13)Large sum
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...
- jquery删除动态增加的li
<script type="text/jscript"> //楼主帮你修改调整了下 $(document).ready(function () { $('.zuo li ...
- HDU Good Numbers (热身赛2)
转载请注明出处:http://blog.csdn.net/a1dark 分析:一道水题.找下规律就OK了.不过要注意特判一下0.因为0也是good number.这个把我坑惨了= =||| #incl ...
- include与jsp:include区别
jsp 中include有两种形式,分别是 <%@ include file=” ”%> <jsp:include page=” ” flush=”true”/> 前者是指令元 ...
- eclipse上 安装php插件
首先在安装之前需要有eclipse 以及SDK环境已经搭建好 eclipse开发工具下载路径: http://dl.oschina.net/soft/eclipse java sdk下载路径: h ...
- 在windows下安装mysql5.6.24版本
链接地址:http://jingyan.baidu.com/article/90bc8fc8615c99f653640cc4.html 工具/原料 官网下载安装包 系统需装net 4.0及以上运行库 ...