林士钧
(林士钧)
1
图形的序列
Problem ID: 9689
Contest ID: 5618
选做题
【题目描述】
现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复;还知道这个长方形的宽和长,编号、长、宽都是整数;现在要求按照一下方式排序(默认排序规则都是从小到大);
1.按照编号从小到大排序
2.对于编号相等的长方形,按照长方形的长排序;
3.如果编号和长都相同,按照长方形的宽排序;
4.如果编号、长、宽都相同,就只保留一个长方形用于排序,删除多余的长方形;最后排好序按照指定格式显示所有的长方形;
【输入】
第一行有一个整数 m
接下来的m(0<m<1000)行,每一行有三个数
第一个数表示长方形的编号;
第二个和第三个数值大的表示长,数值小的表示宽,相等
说明这是一个正方形(数据约定长宽与编号都小于10000);
【输出】
顺序输出每组数据的所有符合条件的长方形的 编号 长 宽
【样例输入】
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
林士钧
(林士钧)
5
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1005
#define INF 0x3f3f3f3f
using namespace std;
struct Rec{
int no;
int len;
int wid;
}rec[MAXN];
bool cmp(Rec a,Rec b){
if(a.no==b.no){
if(a.len==b.len) return a.wid<b.wid;
return a.len<b.len;
}
return a.no<b.no;
}
int main(){
int n;
scanf(“%d”,&n);
while(n–){
int m;
scanf(“%d”,&m);
for(int i=1;i<=m;i++){
scanf(“%d%d%d”,&rec[i].no,&rec[i].len,&rec[i].wid);
if(rec[i].len<rec[i].wid) swap(rec[i].len,rec[i].wid);
}
sort(rec+1,rec+m+1,cmp);
rec[0].no=INF;
for(int i=1;i<=m;i++){
if(rec[i].no!=rec[i-1].no || rec[i].len!=rec[i-1].len || rec[i].wid!=rec[i-1].wid){
printf(“%d %d %d\n”,rec[i].no,rec[i].len,rec[i].wid);
}
}
}
}