set需要自定义struct的排序方式
例如,定义一个struct如下:
struct tri
{
int x, y, z;
friend bool operator < (const tri &a, const tri &b)
{
if (a.x == b.x)
{
if (a.y == b.y) return a.z < b.z;
else return a.y < b.y;
}
else return a.x < b.x;
}
};
此后才能定义元素类型为tri的set:
set<tri> s;
Gym - 101510A Art
思路:对三角形三边排序,从小到大分别为x, y, z
x + y > z则可构成三角形
并将x,y,z作为tri类型,整体插入到set中,从而计算不重复的三角形的个数
C++代码如下:
// 坑:set需要自定义元素排序规则
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
const int maxn = 10;
int a[maxn];
struct tri
{
int x, y, z;
friend bool operator < (c