hrbust 1739 Sort Problem 模拟
来源:互联网 发布:2016淘宝店铺开店流程 编辑:程序博客网 时间:2024/05/16 06:33
Sort ProblemTime Limit: 1000 MSMemory Limit: 65535 KTotal Submit: 343(88 users)Total Accepted: 182(86 users)Rating: Special Judge: YesDescription
You have a sequence of N (1 <= N <= 10 000) numbers (none of the numbers is equal to others), can you let the sequence become ascending within N movements.
InputThere are multiple test cases. The first line is a positive integer T, indicating the number of test cases.
For each test case:
Line 1. A positive integer N.
Line 2. This line contains N integers: a1, a2, ..., ai, ...,an (0 < ai <= 2 000 000 000) separated by space.
For each test case, output m at the first line. m is the times of operation.
Then m lines follows. Each line consists two integer x, y meaning that you will change the number on position x and the number on position y.
332 3 151 2 5 3 41011 3 17 19 7 2 20 15 10 13
Sample Output21 32 323 44 571 63 54 95 66 107 88 10
Source哈理工2013春季校赛 - 现场赛#include<stdio.h>#include<string>#include<algorithm>#include<math.h>#include<string.h>using namespace std;int a[100003],b[100003];int vis[100003];int t;int cu_zu[100003][2];int main(){ scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) {scanf("%d",&a[i]); b[i]=a[i]; }int z=0; sort(b+1,b+n+1); for(int i=1;i<=n;i++) { if(a[i]!=b[i]) { for(int j=i+1;j<=n;j++) { if(b[i]==a[j]) { int t=a[j]; a[j]=a[i]; a[i]=t; cu_zu[z][0]=i; cu_zu[z++][1]=j; } } } } printf("%d\n",z); for(int i=0;i<z;i++) { printf("%d %d\n",cu_zu[i][0],cu_zu[i][1]); } }}
0 0
- hrbust 1739 Sort Problem 模拟
- HRBUST 1180 队列模拟
- HRBUST 1014 模拟
- hrbust 1739
- HRBUST 1652 模拟链表
- HRBUST 1547 模拟链表
- hrbust 2104 Encryption 【模拟+STL】
- hrbust 1594 Gragon Ball【模拟】
- hrbust 1039 修路【二分+模拟】
- hrbust 1000 A+B Problem【明天尽力】
- hrbust 2354 An Easy Geometry Problem
- LeetCode Sort Problem || Sort Colors
- hrbust 哈理工oj 1330 邂逅【模拟】
- hrbust 1415 Elementary arithmetic【高精度模拟】水题
- Hrbust 2313 Circle Fan【模拟+思维】
- One special sort problem
- HRBUST
- HRBUST
- 关于ubuntu上搜狗输入法的配置方法
- 哈夫曼树详解
- 递归经典算法之多转向旋转方阵
- Java图形界面:初次接触
- HTML+CSS+JavaScript网络相册【有缩略图】
- hrbust 1739 Sort Problem 模拟
- CSS3:opacity
- SSL 1662_家庭问题_并查集
- Scala基础应用(2)- 类和对象
- SQLite中的query()参数
- springmvc 框架搭建以及实现定时任务
- 动态URL权限控制
- Android6.0和7.0新特性分析
- lex yacc 学习