1236: Simple Sort

时间限制: 1 Sec  内存限制: 128 MB

提交: 195  解决: 53

[提交][状态][讨论版]

题目描述

     You are given n two-dimension points randomly. Now you are asked to sort them by the following rule. For example , there are two points ,point A(x1,y1) and point B(x2,y2), to be compared.
We define point A is less than point B if x1<x2. When x1 equals to x2, we define point A is less than point B if y1<y2. If x1 equals to x2 and y1 equals to y2, we say point A and point B are equal.
     Now you need to sort the points in non-descending order according the rules.

输入

    There are serval test cases.
    The first line contians a integer t which deticates the number of test cases.
    For each test case, the first line contians a integer n deticating the number of points in the test case. The next n lines contain two integers per line which are the positions of n points.
(0<t<=100, 0<n<=10000, -1000<=x<=1000, -1000<=y<=1000)

输出

For each test case, the first line print "Test case x:" in which number x is the test case number starting from 1. There are n lines following. Print out the result of the sort.

样例输入

3
3
10 2
5 4
3 9
3
7 8
8 4
7 5
1
4 4

样例输出

Test case 1:
3 9
5 4
10 2
Test case 2:
7 5
7 8
8 4
Test case 3:
4 4
#include<stdio.h>
struct point{ int x, y; };
point  a[10000];
void copy(point &k, point& i){
	k.x = i.x;
	k.y = i.y;
}
bool less(point i, point j){
	if (i.x < j.x)return true;
	if (i.x==j.x&&i.y < j.y)return true;
	return false;
}
bool big(point i, point j){
	if (i.x>j.x)return true;
	if (i.x==j.x&&i.y>j.y)return true;
	return false;
}
void sort(int from, int to){
	if (from >= to)return;
	int i = from, j = to;
	point k;
	copy(k, a[from]);
	while (1){
		while (big(a[j], k))j--;
		if (j == i)break;
		copy(a[i], a[j]);
		copy(a[j], k);
		i++;
		while (less(a[i], k))i++;
		if (j == i)break;
		copy(a[j], a[i]);
		copy(a[i], k);
		j--;
	}
	sort(from, i - 1);
	sort(i + 1, to);
}
int main(){
	freopen("in.txt", "r", stdin);
	int t;
	scanf("%d", &t);
	int tt;
	for(tt=1;tt<=t;tt++){
		int n;
		scanf("%d", &n);
		int i;
		for (i = 0; i < n; i++)scanf("%d%d",&a[i].x,&a[i].y);
		sort(0, n - 1);
		printf("Test case %d:\n", tt);
		for (i = 0; i < n; i++)
			printf("%d %d\n", a[i].x, a[i].y);
	}
	return 0;
}

东大OJ-快速排序的更多相关文章

  1. 东大OJ 2SAT 异或

    看了十年才懂懂了十年才会会了十年才会写写了十年才写完写完了十年才能改对 #include<stdio.h> #include<string.h> struct res{ int ...

  2. 东大OJ-Max Area

    1034: Max Area 时间限制: 1 Sec  内存限制: 128 MB 提交: 40  解决: 6 [提交][状态][讨论版] 题目描述 又是这道题,请不要惊讶,也许你已经见过了,那就请你再 ...

  3. 清橙OJ 1082 查找第K小元素 -- 快速排序

    题目地址:http://oj.tsinsen.com/A1082 问题描述 给定一个大小为n的数组s和一个整数K,请找出数组中的第K小元素. 这是一个补充程序的试题,你需要完成一个函数: int fi ...

  4. sort(hdu oj 1425)计数排序和快速排序

    Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0 < n,m < 1000000),第二行包含n个各不 ...

  5. SDUT OJ 数据结构实验之排序八:快速排序

    数据结构实验之排序八:快速排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 给定N ...

  6. 【Tsinghua OJ】灯塔(LightHouse)问题

    描述 海上有许多灯塔,为过路船只照明.从平面上看,海域范围是[1, 10^8] × [1, 10^8] . (图一) 如图一所示,每个灯塔都配有一盏探照灯,照亮其东北.西南两个对顶的直角区域.探照灯的 ...

  7. ACM——快速排序法

    快速排序 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:653            测试通过:297 描述 给定输入排序元素数目 ...

  8. Java 泛型快速排序 以sdut 1196为例

    oj链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1196 Java中,Arrays.so ...

  9. PKU OJ 1002 487-3279

    PKU OJ 1002 487-3279 487-3279 Description Businesses like to have memorable telephone numbers. One w ...

  10. 双基准快速排序(Dual-Pivot Quicksort)(转)

    课本上常见的快速排序都是选择一个枢纽元(Pivot),基于这个枢纽元从前后双向扫描分成大于枢纽元和小于枢纽元的.而从JDK 7开始,java.util.Arrays.sort()使用双基准快速排序(D ...

随机推荐

  1. 【学习笔记】Wireshark的用法

    计算机网络课上,需要我们灵活运用网络协议分析仪wireshark,最近一直在看,感觉有点难,并不是软件本身操作难,而是看懂一大群包的含义难,这个难主要也因为它是全英文的~~.. 好了,大致总结一下,基 ...

  2. memcached在windows下多实例并存

    文章来源:http://blog.csdn.net/xingxing513234072/article/details/39343999 memcached.exe的-d install命令安装时其他 ...

  3. Nagios 自定义插件与安装使用之监控dead datanodes

    现在我使用nagios来监控hadoop的核心进程,rm,nm,dn,nn,zkfc,jn,zk等,但是有时候进程虽然还在,但是日志不刷新,web ui上可以看到有些datanodes节点已经变为de ...

  4. HTTP常见状态码 200 301 302 404 500

    HTTP状态码(HTTP Status Code) 一些常见的状态码为: 一.1开头 1xx(临时响应)表示临时响应并需要请求者继续执行操作的状态代码.代码 说明 100 (继续) 请求者应当继续提出 ...

  5. SSH 整合及注意事项

    Spring 整合 hibernate 配置 1. spring 配置管理datasource 及 sessionFactory 1) 引入相关jdbc配置文件. <context:proper ...

  6. MySQL基础学习总结

    1.MySQL基础概念 mysql逻辑架构如下: 每个客户端连接都会在服务器中拥有一个线程,这个连接的查询只会在这个单独的线程中执行. MySQL是分层的架构.上层是服务器层的服务和查询执行引擎,下层 ...

  7. Oracle的Numer类型与C,C#数据类型对应关系

    最近一直在编和Oracle数据库相关程序.Oracle的Number类型和C语言,C#语言类型的对应关系,在网络上查找很久,也没有找到说明文字.但在http://oracle.chinaitlab.c ...

  8. Codeforces Round #285 (Div.1 B & Div.2 D) Misha and Permutations Summation --二分+树状数组

    题意:给出两个排列,求出每个排列在全排列的排行,相加,模上n!(全排列个数)得出一个数k,求出排行为k的排列. 解法:首先要得出定位方法,即知道某个排列是第几个排列.比如 (0, 1, 2), (0, ...

  9. 微软前 CEO 史蒂姆·鲍尔默:除了我们没人拼得过苹果硬件

    微软通过 Surface Book 正式宣布进军笔记本电脑行业的同时,宣传语表示 Surface Book“比苹果的 MacBook Pro 还要快两倍”. 业界对 Surface Book 的好评连 ...

  10. Font Awesome使用指南

    Font Awesome介绍 Font Awesome是一款很流行的字体图标工具.随着Bootstrap的流行而逐渐被人所认识,现在FontAwesome不仅仅可以在bt上使用,还可以应用在各种web ...