-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0006.cpp
More file actions
63 lines (59 loc) · 1.66 KB
/
Copy path0006.cpp
File metadata and controls
63 lines (59 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <set>
using namespace std;
// 在此处补充你的代码
class Rectangle{
public:
int _a,_b;
Rectangle(int a,int b):_a(a),_b(b){}
friend ostream& operator<<(ostream& os,const Rectangle& r){
os<<r._a * r._b<<' '<<r._a * 2 + r._b * 2;
return os;
}
friend bool operator<(const Rectangle& r1,const Rectangle& r2){
if(r1._a * r1._b > r2._a * r2._b) return true;
else if(r1._a * r1._b == r2._a * r2._b){
if(r1._a + r1._b > r2._a + r2._b) return true;
else return true;
}
else return false;
}
bool operator<(const Rectangle& r){
if(_a * _b > r._a * r._b) return true;
else if(_a * _b == r._a * r._b){
if(_a + _b > r._a + r._b) return true;
else return true;
}
else return false;
}
};
struct Comp{
public:
bool operator()(const Rectangle& r1,const Rectangle& r2){
if(r1._a + r1._b < r2._a + r2._b) return true;
else if(r1._a + r1._b == r2._a + r2._b){
if(r1._a * r1._b < r2._a * r2._b) return true;
else return false;
}
else return false;
}
};
int main() {
multiset<Rectangle> m1;
multiset<Rectangle, Comp> m2;
int n, a, b;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
m1.insert(Rectangle(a, b));
m2.insert(Rectangle(a, b));
}
for (multiset<Rectangle>::iterator it = m1.begin(); it != m1.end(); it++) {
cout << *it << endl;
}
cout << endl;
for (multiset<Rectangle>::iterator it = m2.begin(); it != m2.end(); it++) {
cout << *it << endl;
}
return 0;
}