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

相关推荐
醍醐三叶23 分钟前
C++类与对象--2 对象的初始化和清理
开发语言·c++
phoenix@Capricornus1 小时前
反向传播算法——矩阵形式递推公式——ReLU传递函数
算法·机器学习·矩阵
Magnum Lehar1 小时前
3d游戏引擎EngineTest的系统实现3
java·开发语言·游戏引擎
Inverse1621 小时前
C语言_动态内存管理
c语言·数据结构·算法
数据与人工智能律师1 小时前
虚拟主播肖像权保护,数字时代的法律博弈
大数据·网络·人工智能·算法·区块链
Mcworld8572 小时前
java集合
java·开发语言·windows
成功人chen某2 小时前
配置VScodePython环境Python was not found;
开发语言·python
wuqingshun3141592 小时前
蓝桥杯 16. 外卖店优先级
c++·算法·职场和发展·蓝桥杯·深度优先
海绵宝宝贾克斯儿3 小时前
C++中如何实现一个单例模式?
开发语言·c++·单例模式
YouQian7723 小时前
2025春训第十九场
算法