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/ ...
随机推荐
- mysql ifnull if
IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境. mysq ...
- java实现电脑远程控制完整源代码(转)
Java JDK1.4 的Robot对象,该对象可以完成屏幕图像截取操作,控制鼠标,键盘,如此便可以轻而易举地实现远程服务器的控制.本文向大家介绍如何用Java Robot对象实现远程服务器的控制,并 ...
- gdb图形化调试工具总结
gdb除了命令行方式等的调试之外,还有图形化的调试工具,下面列举一些供参考 1:insight 2: ddd 3: kgdb 4: xxgdb 其它的工具欢迎补充
- 【充电器】小米手机2S电池座充——小米手机官网
ligh@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3 [充电器]小米手机2S电池座充--小米手机官网 小米手机2S电池座 ...
- ligh@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3
ligh@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3
- 数据解析之XML和JSON
1. 解析的基本的概念 解析:从事先规定好的格式中提取数据 解析前提:提前约定好格式,数据提供方按照格式提供数据.数据获取方则按照格式获取数据 iOS开发常见的解析:XML解析.JOSN解析 2. X ...
- HDU 2570:迷瘴
迷瘴 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- HDU 1969(二分法)
My birthday is coming up and traditionally I’m serving pie. Not just one pie, no, I have a number N ...
- chrome 浏览器帐号登录不来,如何解决自己的书签
装系统前把 该目录下 C:\Users\Administrator\AppData\Local\Google\Chrome\User Data\Default 的 Bookmarks 复制出 ...
- static timing analysis 基础
此博文依据 特权同学在电子发烧友上的讲座PPT进行整理而成. static timing analysis 静态时序分析基础 过约束:有不必要的约束,或者是约束不能再某一情况下满足.——约束过头了 ...