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

相关推荐
一然明月6 分钟前
C#语言基础详解和面向对象编程核心概念与高级特性详解(万字详解带示例代码)
开发语言·c#
武帝为此8 分钟前
【RC4加密算法介绍】
网络·python·算法
宵时待雨9 分钟前
数据结构(初阶)笔记归纳4:单链表的实现
c语言·开发语言·数据结构·笔记·算法
WHOVENLY13 分钟前
揭秘正则表达式的基础语法与应用
开发语言·javascript·正则表达式
大雨淅淅14 分钟前
【开发工具】Postman从入门到精通:环境搭建与使用全攻略
开发语言·lua
flysh0518 分钟前
.NET 基础 - StringBuilder 类
开发语言·c#·编程语言·c#10
BLSxiaopanlaile26 分钟前
关于子集和问题的几种解法
数据结构·算法·剪枝·回溯·分解
甄心爱学习32 分钟前
Python 中 combinations 的详细用法
开发语言·python
狐5735 分钟前
2026-01-17-LeetCode刷题笔记-3047-求交集区域内的最大正方形面积
笔记·算法·leetcode
独自归家的兔38 分钟前
Java性能优化实战:从基础调优到系统效率倍增 -2
java·开发语言·性能优化