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

相关推荐
weixin_4565881511 小时前
JVM(java虚拟机)
java·开发语言·jvm
hygge99911 小时前
JVM 内存结构、堆细分、对象生命周期、内存模型全解析
java·开发语言·jvm·经验分享·面试
小二·11 小时前
Java虚拟机(JVM)面试题(51道含答案)
java·开发语言·jvm
无敌最俊朗@11 小时前
03-事务高频面试总结
java·开发语言·jvm
hygge99911 小时前
类加载机制、生命周期、类加载器层次、JVM的类加载方式
java·开发语言·jvm·经验分享·面试
修行者Java11 小时前
JVM 垃圾回收算法的详细介绍
jvm·算法
AndrewHZ11 小时前
【图像处理基石】什么是光流法?
图像处理·算法·计算机视觉·目标跟踪·cv·光流法·行为识别
mjhcsp12 小时前
C++ 三分查找:在单调与凸函数中高效定位极值的算法
开发语言·c++·算法
我命由我1234512 小时前
Element Plus 组件库 - Select 选择器 value 为 index 时的一些问题
开发语言·前端·javascript·vue.js·html·ecmascript·js
沐知全栈开发12 小时前
MySQL 删除数据库指南
开发语言