日常练习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;
}
相关推荐
漫随流水16 分钟前
leetcode算法(151.反转字符串中的单词)
数据结构·算法·leetcode
ada7_31 分钟前
LeetCode(python)78.子集
开发语言·数据结构·python·算法·leetcode·职场和发展
DeepVis Research43 分钟前
【AGI/Simulation】2026年度通用人工智能图灵测试与高频博弈仿真基准索引 (Benchmark Index)
大数据·人工智能·算法·数据集·量化交易
努力学算法的蒟蒻1 小时前
day52(1.3)——leetcode面试经典150
算法·leetcode·面试
leoufung1 小时前
LeetCode 97. 交错字符串 - 二维DP经典题解(C语言实现)
c语言·算法·leetcode
leiming63 小时前
c++ map容器
开发语言·c++·算法
杨校4 小时前
杨校老师课堂备赛C++信奥之模拟算法习题专项训练
开发语言·c++·算法
世洋Blog4 小时前
AStar算法基础学习总结
算法·面试·c#·astar·寻路
haing20194 小时前
七轴协作机器人运动学正解计算方法
算法·机器学习·机器人
谈笑也风生4 小时前
把二叉搜索树转换为累加树(一)
算法