日常练习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;
}
相关推荐
Tisfy12 分钟前
LeetCode 3882.网格图中最小异或路径:动态规划
算法·leetcode·动态规划
D e re k ZH1 小时前
P5025 [SNOI2017] 炸弹
c++·算法
A boy CDEF girl1 小时前
算法题专栏:优选算法
数据结构·算法·leetcode
没落之王1 小时前
三易五行看宋朝的三界确立
大数据·人工智能·算法
坤坤子吖2 小时前
算法学习——单调队列
开发语言·c++·笔记·学习·算法
Js.Tx3 小时前
【具体数学 Concrete Mathematics】2.1.5 一般性的方法
算法·具体数学
秋天的怀念_David5 小时前
算法一千零一夜 · 作品相关:版权与致谢声明
程序人生·算法·学习方法
揽星河..5 小时前
【C语言】数组
c语言·开发语言·算法
careathers5 小时前
【数据结构】基于比较的排序算法 - 选择排序
数据结构·算法·排序算法
听风若依5 小时前
C++模板初阶
c++·算法