关于运算符重载
  • 板块P2123 皇后游戏
  • 楼主imfkwk
  • 当前回复4
  • 已保存回复4
  • 发布时间2021/7/30 01:48
  • 上次更新2023/11/4 12:42:49
查看原帖
关于运算符重载
389540
imfkwk楼主2021/7/30 01:48

根据已知的排序规则重载运算符。

struct node
{
	int l,r;
	bool operator<(const node x)const
	{
		if(l<r&&x.l>=x.r)return 1;
		if(l>r&&x.l<=x.r)return 0;
		
		if(l<r&&x.l<x.r)
		{
			return l<x.l;
		}
		if(l>r&&x.l>x.r)
		{
			return r>x.r;
		}
	}
}p[20001];

但是提交之后会有4哥点RE。

struct node
{
	int l,r;
	bool operator<(const node x)const
	{
		if(l<r&&x.l>=x.r)return 1;
		if(l>r&&x.l<=x.r)return 0;
		
		if(l<r&&x.l<x.r)
		{
			return l<x.l;
		}
		if(l>r&&x.l>x.r)
		{
			return r>x.r;
		}
		
		if(l==r&&x.l==x.r)return 1;
	}
}p[20001];

需要加上一句if(l==r&&x.l==x.r)return 1;才不会RE。但是上面的四个return已经把剩下的条件排除到了l==r&&x.l==x.r,所以为什么需要这样写才能避免RE呢?

蒟蒻の求助orz

2021/7/30 01:48
加载中...