东大OJ-快速排序
1236: Simple Sort
时间限制: 1 Sec 内存限制: 128 MB
提交: 195 解决: 53
[提交][状态][讨论版]
题目描述
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.
输入
(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-快速排序的更多相关文章
- 东大OJ 2SAT 异或
看了十年才懂懂了十年才会会了十年才会写写了十年才写完写完了十年才能改对 #include<stdio.h> #include<string.h> struct res{ int ...
- 东大OJ-Max Area
1034: Max Area 时间限制: 1 Sec 内存限制: 128 MB 提交: 40 解决: 6 [提交][状态][讨论版] 题目描述 又是这道题,请不要惊讶,也许你已经见过了,那就请你再 ...
- 清橙OJ 1082 查找第K小元素 -- 快速排序
题目地址:http://oj.tsinsen.com/A1082 问题描述 给定一个大小为n的数组s和一个整数K,请找出数组中的第K小元素. 这是一个补充程序的试题,你需要完成一个函数: int fi ...
- sort(hdu oj 1425)计数排序和快速排序
Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0 < n,m < 1000000),第二行包含n个各不 ...
- SDUT OJ 数据结构实验之排序八:快速排序
数据结构实验之排序八:快速排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description 给定N ...
- 【Tsinghua OJ】灯塔(LightHouse)问题
描述 海上有许多灯塔,为过路船只照明.从平面上看,海域范围是[1, 10^8] × [1, 10^8] . (图一) 如图一所示,每个灯塔都配有一盏探照灯,照亮其东北.西南两个对顶的直角区域.探照灯的 ...
- ACM——快速排序法
快速排序 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:653 测试通过:297 描述 给定输入排序元素数目 ...
- Java 泛型快速排序 以sdut 1196为例
oj链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1196 Java中,Arrays.so ...
- PKU OJ 1002 487-3279
PKU OJ 1002 487-3279 487-3279 Description Businesses like to have memorable telephone numbers. One w ...
- 双基准快速排序(Dual-Pivot Quicksort)(转)
课本上常见的快速排序都是选择一个枢纽元(Pivot),基于这个枢纽元从前后双向扫描分成大于枢纽元和小于枢纽元的.而从JDK 7开始,java.util.Arrays.sort()使用双基准快速排序(D ...
随机推荐
- android oncreate获取宽高度
gridView = (GridView) getView().findViewById(R.id.gridView_musicbook); gridView.getViewTreeObserver( ...
- 2-Fedora 17系统安装准备
在安装Fedora 17系统之前应做好准备工作,这些准备工作包括了解安装系统的硬件要求,Linux系统磁盘分区方案和挂载目录以及制作安装引导盘 学习重点: 硬件要求 硬件兼容性 分区方案 学习内容: ...
- Docker+OpenvSwitch搭建VxLAN实验环境
一.概述 1.环境:我这里是2台linux机器(host1和host2),发行版是kali2.0, ...
- [Notes] Learn Python2.7 From Python Tutorial
I have planed to learn Python for many times. I have started to learn Python for many times . Howeve ...
- VS 的编译选项 build下的 platform target -- Any CPU和x86有什么影响?
VS 的编译选项 build下的platform -- Any CPU和x86有什么影响? 现在的问题是,我的一个assembly用Any CPU编译就不能在64位系统下运行了,但是用x86编译就ok ...
- UNITY 2D入门基础教程
Unity4.3增加了原生的2D开发环境,新建项目时选2D http://blog.1vr.cn/?p=1422
- Qt 静态编译后的exe太大, 可以这样压缩.
1. 下载PECompact 下载地址:http://download.csdn.net/download/sniper_bing/7669247 , 不行大家就去baidu搜索下载就可以了这个是绿 ...
- FragmentTransaction.replace() 你不知道的坑
一.起源: 先看效果,在linearLayout中添加了4个Fragment,然后点击替换一次确替换了两个Fragment,引发了我的研究兴趣: 第一次启动 ...
- http协议(五)web服务器
1.http1.1规范允许一台http服务器搭建多个web站点... 比如提供web托管服务的供应商,可以用一台服务器为多为客户服务,也可以以每位客户持有的域名运行各自不同的网站,这里利用了虚拟服务器 ...
- 启动Eclipse后卡在 android sdk content loader 的解决办法
Make sure that eclipse is not active. If it is active kill eclipse from the processes tab of the tas ...