AI识别面板

#include<iostream>

#include<vector>

#include<algorithm>

using namespace std;

struct Light

{

int id;

int x;

int y;

int r;

Light(int id, int x, int y, int r) : id(id), x(x), y(y), r(r)

{

}

};

bool compareByY(const Light& a, const Light& b)

{

return a.y < b.y;

}

bool compareByX(const Light& a, const Light& b)

{

return a.x < b.x;

}

int main()

{

int n;

cin >> n;

vector<Light> lights;

for(int i = 0; i < n; i++)

{

int id;

int x1;

int y1;

int x2;

int y2;

cin >> id >> x1 >> y1 >> x2 >> y2;

int x = (x1 + x2) / 2;

int y = (y1 + y2) / 2;

int r = (x2 - x1) / 2;

lights.emplace_back(id, x, y, r);

}

sort(lights.begin(), lights.end(), compareByY);

for(int i = 0; i < n; i++)

{

cout << lights[i].id << " ";

}

cout << endl;

string result;

int rowStartIndex = 0;

for(int i = 1; i < n; i++)

{

if(lights[i].y - lights[rowStartIndex].y > lights[rowStartIndex].r)

{

sort(lights.begin() + rowStartIndex, lights.begin() + i - 1, compareByX);

for(int j = rowStartIndex; j < i; j++)

{

result += to_string(lights[j].id) + " ";

}

rowStartIndex = i;

}

}

sort(lights.begin() + rowStartIndex, lights.end(), compareByX);

for(int i = rowStartIndex; i < n; i++)

{

result += to_string(lights[i].id) + " ";

}

cout << result << endl;

return 0;

}

5

1 0 0 2 2

2 3 0 5 3

3 6 0 8 2

4 0 6 2 7

5 4 6 6 7

1 2 3 4 5

5

1 0 0 2 2

2 6 1 8 3

3 3 2 5 4

5 5 4 7 6

4 0 4 2 6

1 2 3 4 5

相关推荐
咩咩大主教几秒前
2025最新版使用VSCode和CMake图形化编译调试Cuda C++程序(保姆级教学)
c++·vscode·cmake·visual studio·cuda·cpp·cuda c++
是紫焅呢12 分钟前
F接口基础.go
开发语言·后端·青少年编程·golang·visual studio code
幻奏岚音14 分钟前
Java数据结构——第 2 章线性表学习笔记
java·数据结构·笔记·学习·算法·排序算法
CoovallyAIHub17 分钟前
YOLOv8/v10/v11自动驾驶实测对比:揭秘v11遮挡车辆检测精度提升关键
深度学习·算法·计算机视觉
虾球xz20 分钟前
CppCon 2017 学习:folly::Function A Non-copyable Alternative to std::function
开发语言·c++·学习
程序员弘羽23 分钟前
extern关键字:C/C++跨文件编程利器
c语言·开发语言·c++
Hesse28 分钟前
Fast DDS v2.8.2 数据流程代码解析
c++·后端
TGB-Earnest38 分钟前
【leetcode-两两交换链表中的节点】
算法·leetcode·链表
听忆.39 分钟前
Java修改接口 校验一个或多个字段不可重复(自定义注解)
java·开发语言·数据库
dying_man1 小时前
LeetCode--34.在排序数组中查找元素的第一个和最后一个位置
算法·leetcode