日常练习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;
}
相关推荐
偷偷的卷13 分钟前
【算法笔记 11】贪心策略六
笔记·算法
ZPC82101 小时前
FPGA 部署ONNX
人工智能·python·算法·机器人
_w_z_j_1 小时前
爱丽丝的人偶
算法
老前端的功夫2 小时前
Vue2中key的深度解析:Diff算法的性能优化之道
前端·javascript·vue.js·算法·性能优化
yongui478342 小时前
基于深度随机森林(Deep Forest)的分类算法实现
算法·随机森林·分类
是苏浙3 小时前
零基础入门C语言之C语言实现数据结构之单链表经典算法
c语言·开发语言·数据结构·算法
橘颂TA3 小时前
【剑斩OFFER】算法的暴力美学——点名
数据结构·算法·leetcode·c/c++
MATLAB代码顾问4 小时前
多种时间序列预测算法的MATLAB实现
开发语言·算法·matlab
高山上有一只小老虎5 小时前
字符串字符匹配
java·算法
愚润求学6 小时前
【动态规划】专题完结,题单汇总
算法·leetcode·动态规划