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. ELK Nxlog->Kafka->ElasticSearch

    Windows 系统下,log4日志通过kafka发送到elasticsearch; windows 下nxlog没有找到直接发送数据到kafka的插件,所以采用logstash中转下     Nxl ...

  2. XP系统下IIS常见的几个问题

    随笔说明: 个人笔记.仅供参考 根据日常遇到的相关问题不定期增改 时间:2015年1月7日23:09 Soft:Microsoft .NET Framework 4(独立安装程序) Microsoft ...

  3. Linux nm命令

    一.简介 显示关于对象文件.可执行文件以及对象文件库里的符号信息. 二.选项 http://www.cnblogs.com/wangkangluo1/archive/2012/07/02/257243 ...

  4. Android ViewPager初探:让页面滑动起来

    下一篇:<Android ViewPager再探:增加滑动指示条> ViewPager需要用到适配器PagerAAdapter,以下四个函数需要重写: instantiateItem(Vi ...

  5. FineReport集成到AWS系统中的方案

    本人实施了北京炎黄盈动的BPM及OA系统,主要目标是对业务流程进行控制和管理,加快Oracle JDE的业务前端录单速度和弥补JDE在流程控制方面的不足,实现BPM数据能与JDE无缝互相结合,经过3个 ...

  6. python中strip,lstrip,rstrip简介

    一.起因 今天在做角色控制中,有一个地方用到rstrip,判断用户请求的url是否与数据库对应可用权限中url相符. if request.path == x.url or request.path. ...

  7. javaScript事件(五)事件类型之鼠标事件

    一.事件 二.事件流 以上内容见:javaScript事件(一)事件流 三.事件处理程序 四.IE事件处理程序 以上内容见javaScript事件(二)事件处理程序 五.事件对象 以上内容见javaS ...

  8. plain framework 1 参考手册 入门指引之 简明教程

    简明教程 简单的例子 实现代码 简单的例子 如果你已经下载好整个框架的源码,那么你可以在这里找到应用的例子: plainframework/applications/pf_simple 如果你在win ...

  9. Java Web之Servlet技术

    1.Servlet基础 针对Servlet技术开发,Sun公司提供了一些列接口和类,其中最重要的是javax.servlet.Servlet接口,两个重要的包是javax.servlet和javax. ...

  10. Caffe 抽取CNN网络特征 Python

    Caffe Python特征抽取 转载请注明出处,楼燚(yì)航的blog,http://www.cnblogs.com/louyihang-loves-baiyan/ Caffe大家一般用到的深度学 ...