您的位置:首页 > 文旅 > 美景 > 西地那非使用三大忌_ai一键生成短视频免费版_企业宣传软文范例_完美日记网络营销策划书

西地那非使用三大忌_ai一键生成短视频免费版_企业宣传软文范例_完美日记网络营销策划书

2025/2/26 14:09:39 来源:https://blog.csdn.net/m0_70882914/article/details/142369702  浏览:    关键词:西地那非使用三大忌_ai一键生成短视频免费版_企业宣传软文范例_完美日记网络营销策划书
西地那非使用三大忌_ai一键生成短视频免费版_企业宣传软文范例_完美日记网络营销策划书

1. 1459.矩形面积

1.1 题干

表: Points

±--------------±--------+
| Column Name | Type |
±--------------±--------+
| id | int |
| x_value | int |
| y_value | int |
±--------------±--------+
id 是该表中具有唯一值的列。
每个点都用二维坐标 (x_value, y_value) 表示。

编写解决方案,报告由表中任意两点可以形成的所有 边与坐标轴平行 且 面积不为零 的矩形。

结果表中的每一行包含三列 (p1, p2, area) 如下:

p1 和 p2 是矩形两个对角的 id
矩形的面积由列 area 表示
返回结果表请按照面积 area 大小 降序排列;如果面积相同的话, 则按照 p1 升序排序;若仍相同,则按 p2 升序排列。

返回结果格式如下例所示:

示例 1:
在这里插入图片描述
输入:
Points 表:
±---------±------------±------------+
| id | x_value | y_value |
±---------±------------±------------+
| 1 | 2 | 7 |
| 2 | 4 | 8 |
| 3 | 2 | 10 |
±---------±------------±------------+
输出:
±---------±------------±------------+
| p1 | p2 | area |
±---------±------------±------------+
| 2 | 3 | 4 |
| 1 | 2 | 2 |
±---------±------------±------------+
解释:
p1 = 2 且 p2 = 3 时, 面积等于 |4-2| * |8-10| = 4
p1 = 1 且 p2 = 2 时, 面积等于 ||2-4| * |7-8| = 2
p1 = 1 且 p2 = 3 时, 是不可能为矩形的, 面积等于 0

1.2 准备数据

Create table If Not Exists Points (id int, x_value int, y_value int)
Truncate table Points
insert into Points (id, x_value, y_value) values ('1', '2', '7')
insert into Points (id, x_value, y_value) values ('2', '4', '8')
insert into Points (id, x_value, y_value) values ('3', '2', '10')

1.3 实现

#方式一
with t1 as (select p1.id as p1,p2.id as p2,abs((p1.x_value-p2.x_value)*(p1.y_value-p2.y_value)) area
from points p1 cross join points p2
)
select distinct  least(p1,p2) as p1,greatest(p1,p2) as p2,area from t1 where area > 0
order by area desc,p1 asc,p2 asc;# 方式二with t1 as (select p1.id as p1,p2.id as p2,abs((p1.x_value-p2.x_value)*(p1.y_value-p2.y_value)) area
from points p1 cross join points p2
on p1.id <p2.id and p1.x_value <> p2.x_value and p1.y_value <> p2.y_value
)
select distinct  p1,p2,area from t1 where area > 0order by area desc,p1 asc,p2 asc;

1.4 结果截图

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com