题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=8
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 <cstdlib> #include <cstring> #include <algorithm> #include <cstdio> #include <cmath> #include <iostream> #include <vector> #include<string> #include<cstring> #include<string.h> #include<set> #include<queue> using namespace std; typedef long long ll; class Node{ public: int id; int length; int weight; public: Node(){} Node(int a, int b, int c):id(a),length(b),weight(c){} int operator<(const Node &s)const { if(id==s.id) { if(length==s.length) return weight<s.weight; return length<s.length; } else return id<s.id; } bool operator ==(const Node &s) { return id==s.id&& length==s.length &&weight==s.weight; } friend ostream& operator<<(ostream &os, const Node &s){ os<<s.id<<" "<<s.length<<" "<<s.weight<<endl; return os; } }; int main() { int t; cin>>t; while(t--) { set<Node>myset; set<Node>::iterator it; int n; int id,a,b,Max,Min; cin>>n; for(int i=0;i<n;i++) { cin>>id>>a>>b; Max=a>=b?a:b; Min=a<b?a:b; myset.insert(Node(id,Max,Min)); } for(it=myset.begin(); it != myset.end(); it++) { cout<<*it; } } return 0; }
一种排序 set<stl> 无重复 + < 符号重载 ==,布布扣,bubuko.com
原文:http://www.cnblogs.com/zn505119020/p/3620486.html