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/ ...
随机推荐
- Qt 技巧:设置在 debug 路径下直接运行可执行文件
Qt 编译的时候默认会使用影子构建,这时在工作路径下会生成一个目录:xxx-build-desktop-xxx. 如果编译通过,在该目录下会生成一个可执行文件,双击之,但不能运行,提示是缺少某个动态库 ...
- mongodb 限制ip访问
<pre name="code" class="python">一.限制访问IP和端口 MongoDB可以限制只允许某一特定IP来访问,只要在启动时 ...
- BZOJ 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课
题目 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课 Time Limit: 5 Sec Memory Limit: 64 MB Description 考虑一 ...
- (step6.3.5)hdu 1281(棋盘游戏——二分图的完美匹配)
题目大意:本体是中文题.读者可以直接在OJ上看 解题思路: 1)完美匹配:所有的端点都是匹配点 2)对于二分图的完美匹配,我们需要用一个数组来存储匹配点.(而二分图的其他问题(我们则可以直接使用变量来 ...
- 整合SSH三大框架用注解时报An AnnotationConfiguration instance is required to use
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 's ...
- stm32之中断系统
概述: 提供中断控制器,用于总体管理异常,称之为“嵌套向量中断控制器:Nested Vectored Interrupt Controller (NVIC) VIC:中断管理器: NVIC:内嵌中断管 ...
- [HDU 1016]--Prime Ring Problem(回溯)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016 Prime Ring Problem Time Limit: 4000/2000 MS (Jav ...
- 统计图表类库--libchart使用简介
1.饼图 #载入类文件 include "../libchart/classes/libchart.php"; header("Content-type: image/p ...
- python中enumerate 函数
enumerate 函数用于遍历序列中的元素以及它们的下标: >>> for i,j in enumerate(('a','b','c')): print i,j 0 a 1 b ...
- vim 小技巧总结
1.v+移动光标可以选中文本. 2.y可以复制已经选中的文本 3.p可以粘贴 复制一行则:yy 复制当前光标所在的位置到行尾:y$ 复制当前光标所在的位置到行首:y^ 复制三行则:3yy,即从当前光标 ...