关闭

nyoj--233--Sort it (水题)

482人阅读 评论(0) 收藏 举报
分类:

Sort it

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述
You want to processe a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. Then how many times it need.
For example, 1 2 3 5 4, we only need one operation : swap 5 and 4.
输入
The input consists of a number of test cases. Each case consists of two lines: the first line contains a positive integer n (n <= 1000); the next line contains a permutation of the n integers from 1 to n.
输出
For each case, output the minimum times need to sort it in ascending order on a single line.
样例输入
3
1 2 3
4 
4 3 2 1 
样例输出
0
6
来源
ZJFC 2009-3 Programming Contest
上传者

张洁烽



好久以前没做出来的题,清理一下,的确是有点水

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define MAX 100100
int num[MAX]; 
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
		scanf("%d",&num[i]);
		int sum=0;
		int t;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(num[i]>num[j])
				{
					t=num[i],num[i]=num[j],num[j]=t;
					sum++;
				}
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}



0
0
查看评论

HDU 2689

Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3379    Accep...
  • a73265
  • a73265
  • 2015-08-03 19:01
  • 246

Sort it

Sort it 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述You want to processe a sequence of n distinct integers by swapping two ...
  • l2533636371
  • l2533636371
  • 2017-09-12 21:23
  • 135

poj 1094 Sorting It All Out(拓扑排序)

链接: http://poj.org/problem?id=1094 题目: Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total ...
  • shuangde800
  • shuangde800
  • 2012-09-08 10:04
  • 2455

ACM-Sort it

描述 You want to processe a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order....
  • u012701023
  • u012701023
  • 2015-05-27 08:51
  • 470

HDU 2689 Sort it(树状数组求逆序数)

Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3418  ...
  • yeguxin
  • yeguxin
  • 2015-08-19 16:27
  • 773

hdu 2689 Sort it 一维树状数组的应用

Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3388  ...
  • ruangongshi
  • ruangongshi
  • 2015-08-10 21:37
  • 238

Just Sort It(快速排序)

Judge Info Memory Limit: 1124KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Judger Description Sorting is one...
  • piekey1994
  • piekey1994
  • 2014-08-08 20:50
  • 249

poj水题

此类的题目都是刚学C语言不久刚接触ACM的时候做的。。完全没算法。。最多有点小技巧。。 题型很杂。。 评述的话主要是自己以后找起题来方便。。大牛们忽略就好。。 1000  纯属适应题 1003  做的时候花了很久,现在看好像也不难 1004  适应...
  • qq429205464
  • qq429205464
  • 2011-08-30 16:14
  • 5782

只会做水题-

都是水题   15.11.09数字为POJ题号  ------------------------11.91003 1004100510071006 中国剩余定理1001  浮点数高精度计算 1002 map映射-------------------...
  • viphong
  • viphong
  • 2018-02-08 00:50
  • 2027

HDU - 2689 Sort it

Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4980  ...
  • Lngxling
  • Lngxling
  • 2017-09-20 22:11
  • 77
    个人资料
    • 访问:163308次
    • 积分:7653
    • 等级:
    • 排名:第3342名
    • 原创:628篇
    • 转载:7篇
    • 译文:0篇
    • 评论:23条
    最新评论