acm练习:矩形排序
来源:互联网 发布:淘宝申请售后服务培训 编辑:程序博客网 时间:2024/05/21 17:09
时间限制:3000 ms | 内存限制:65535 KB
难度:3
描述
现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复;还知道这个长方形的宽和长,编号、长、宽都是整数;现在要求按照一下>方式排序(默认排序规则都是从小到大);
1.按照编号从小到大排序
2.对于编号相等的长方形,按照长方形的长排序;
3.如果编号和长都相同,按照长方形的宽排序;
4.如果编号、长、宽都相同,就只保留一个长方形用于排序,删除多余的长方形;最后排好序按照指定格式显示所有的长方形;
输入
第一行有一个整数 0
输出
顺序输出每组数据的所有符合条件的长方形的 编号 长 宽
样例输入
1
8
1 1 1
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
样例输出
1 1 1
1 2 1
1 2 2
2 1 1
2 2 1
我的代码:
#include<stdio.h>struct rectangle { int id; int length; int width; int repetition; int reverse;};struct rectangle a[1000];void exch(struct rectangle *a,int i) {struct rectangle ra=a[i];a[i]=a[i-1];a[i-1]=ra;}void funk1();int comp(int,struct rectangle *); int main() { int n; scanf("%ld",&n); while(n--) funk1(); return 0;}int comp(int i,struct rectangle *a) {return (a[i].id<a[i-1].id)?1:((a[i].id>a[i-1].id)?0:((a[i].length>a[i-1].length)?0:((a[i].length<a[i-1].length)?1:((a[i].width>a[i-1].width)?0:((a[i].width<a[i-1].width)?1:2)))));}void funk1() { int m,i,j,k; scanf("%ld",&m); for(i=0;i<m;i++) { a[i].repetition=0; a[i].reverse=0; scanf("%ld %ld %ld",&a[i].id,&a[i].length,&a[i].width); if(a[i].width>a[i].length) { k=a[i].length; a[i].length=a[i].width; a[i].width=k; a[i].reverse=1; } } for(i=m-1;i>0;i--) { k=comp(i,a); switch(k) { case 1:exch(a,i);break; case 2:a[i].repetition=1; break; } } for(i=2;i<m;i++) { for(j=i;k=comp(j,a);j--) { switch(k) { case 1:exch(a,j);break; case 2:a[j].repetition=1; break; } } } for(i=0;i<m;i++) { if(a[i].repetition==1) continue; printf("%ld %ld %ld\n",a[i].id,a[i].length,a[i].width); } }
阅读全文
0 0
- acm练习:矩形排序
- ACM练习-ASCII码排序
- ACM练习—三个数从小到大排序
- 练习场acm 题目8 一种排序
- 第十六周自由练习项目——acm 长方体继承自矩形
- ACM 矩形类定义
- 【ACM】最大的矩形
- ACM-矩形的个数
- ACM最大矩形
- ACM:J: 矩形着色
- ACM 练习
- acm 练习
- ACM-选夫婿(结构体排序练习)
- 练习 2.3 定义矩形
- 矩形嵌套问题-ACM集训
- ACM:蓝桥杯:矩形的个数
- ACM:蓝桥杯:矩形面积交
- 基础练习 矩形面积交
- linux编程之基本锁、循环锁
- 日记8/5
- default constructor not found解决方法
- JavaScript趣味编程--仿微信飞机大战游戏--2.让飞机移动
- 《Python 基础教程》学习笔记(一)
- acm练习:矩形排序
- eclipse软件安装流程
- 在window7系统下打开chm文档的时候提示:找不到mk:@MSITStore:(文件路径)
- 初学安卓开发随笔之 Intent 用法
- 士兵杀敌(三)
- JavaScript数组去重
- 反码补码原码
- poj-1860 Currency Exchange (货币转换—最长路)
- Python学习(十一)——matplotlib与可视化