Codeforces Round #277.5 (Div. 2) A SwapSort 我自己写的奇葩代码竟然AC了。。。自己都觉得不可思议
来源:互联网 发布:淘宝客宣传海报 编辑:程序博客网 时间:2024/04/28 21:34
就是模拟,考察基本功的题
题目大意:给n个数,输出最少交换次数以及每一次都交换第几个和第几个数(的下标,并且下标从[0~n) )
就这样......
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <vector>#include <cmath>#include <queue>#include <cstdlib>#include <algorithm>#define maxn 0XFFFFF #define MAX 0xFFFFFFF#define lson l,m,t<<1#define rson m+1,r,t<<11using namespace std;struct node{int tou;int wei;}nd[3100];int a[3200],b[3200],n;int main(int argc, char *argv[]){while(scanf("%d",&n)!=EOF){for(int i = 0 ; i < n ; i++){scanf("%d",&a[i]);b[i] = a[i];} sort(b,b+n);int t = 0,i = 0;while(i != n){for(int j = 0 ; j < n ; j++){ if(a[j] != b[j]) { i = j; break; } if(j == n-1) i = n;} for(int p = i+1 ; p < n ; p++){ if(a[p] == b[i]) { int w = a[i]; a[i] = a[p]; a[p] = w; nd[t].tou = i; nd[t].wei = p; t++; break; }}}printf("%d\n",t);for(int i = 0 ; i < t ; i++)printf("%d %d\n",nd[i].tou,nd[i].wei);}return 0;}
0 0
- Codeforces Round #277.5 (Div. 2) A SwapSort 我自己写的奇葩代码竟然AC了。。。自己都觉得不可思议
- Codeforces Round #277.5 (Div. 2)A. SwapSort
- Codeforces Round #277.5 (Div. 2)A——SwapSort
- Codeforces Round #277.5 (Div. 2)---A. SwapSort (sort)
- 写了一个自己都觉得陌生的程序
- Codeforces #277.5 (Div. 2) A. SwapSort(基础:选择排序)
- 我不会代码设计--看着自己写的稀烂的代码 想哭了都。。
- 这样的萧澈,让皇帝自己都觉得有些不可思议
- 我自己觉得不太好的代码一览:
- 丢人了!英伟达抄代码也就算了,竟然把人家的License都改成自己的
- 丢人了!英伟达抄代码也就算了,竟然把人家的License都改成自己的
- 突然觉得我要写自己的Blog
- 其实我真是觉得我应该写一篇总结来总结一下自己的生活的了
- 你觉得自己喜欢写代码吗?
- 自定义View---五子棋盘(自己敲了一下午,然后百度了一下,竟然有,比我自己写的好很多。好尴尬)
- 为什么我写了半年程序,还是觉得自己像是一无所知呢
- 我觉得自己...
- 自己写的代码终于写完了
- sublime常用插件
- .vimrc 备份
- HDU4451Dressing(计数)
- 如何分析解决Android ANR
- 2014年11月20微我正式上线
- Codeforces Round #277.5 (Div. 2) A SwapSort 我自己写的奇葩代码竟然AC了。。。自己都觉得不可思议
- OpenCV实现对图像的光照归一化处理
- ZK SpreadSheet PWC2788: setAttribute: Non-serializable attribute with name javax.zkoss.zk.ui.Session
- jQuery数组处理详解
- bzoj 1072: [SCOI2007]排列perm
- 降落伞充气过程仿真(源码)
- Linux 下定时器的实现方式分析
- 8640 希尔排序
- 重复(视频)文件删除软件