日常练习2

排序+暴力

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

int n;
const int N = 1e3+5;
struct node{
	int l,r,h,pos;
	bool operator<(node b){
		if(h>b.h) return 1;
		return h== b.h ? pos < b.pos : 0;
	}
}sto[N];
int ans[N][2];

int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> sto[i].h >> sto[i].l >> sto[i].r;
		sto[i].pos = i;
	}
	sort(sto+1,sto+1+n);
	for(int i=1;i<=n;i++){
		int h = sto[i].h, l = sto[i].l ,r = sto[i].r,pos = sto[i].pos;
		//cout << h << " " << l << " " << r << " " << endl;
		int flagl = 1, flagr = 1;
		for(int j=i+1;j<=n;j++){
			if(h==sto[j].h) continue;
			int ll = sto[j].l , rr = sto[j].r, ppos = sto[j].pos;
			if(flagl){
				if(l>ll&&l<rr){
					ans[pos][0] = ppos; flagl = 0;
				}
			}
			if(flagr){
				if(r>ll&&r<rr){
					ans[pos][1] = ppos; flagr = 0;
				}
			}
			if(flagl==0 && flagr==0) break;
		}
	}
	for(int i=1;i<=n;i++){
		cout << ans[i][0] << " " << ans[i][1] << endl;
	}
	return 0;
}
相关推荐
蒟蒻的贤1 小时前
leetcode链表
算法·leetcode·链表
Funny_AI_LAB1 小时前
AI Agent最新重磅综述:迈向高效智能体,记忆、工具学习和规划综述
人工智能·学习·算法·语言模型·agi
执着2591 小时前
力扣hot100 - 94、二叉树的中序遍历
数据结构·算法·leetcode
-dzk-1 小时前
【代码随想录】LC 707.设计链表
数据结构·c++·算法·链表
Dave.B2 小时前
vtkPolyDataConnectivityFilter 实用指南
算法·vtk
细节处有神明2 小时前
开源数据之历史气象数据的获取与使用
人工智能·python·算法
小白开始进步3 小时前
JAKA Zu12 机械臂运动学算法深度解析(含可视化方案)
python·算法·numpy
梵刹古音3 小时前
【C语言】 递归函数
c语言·数据结构·算法
yongui478343 小时前
混凝土二维随机骨料模型 MATLAB 实现
算法·matlab