日常练习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;
}
相关推荐
一去不复返的通信er3 分钟前
力扣-图论-岛屿数量
算法·leetcode·图论
程序 代码狂人3 小时前
切片表与分区表的区别(数据开发面试版)
java·大数据·开发语言·数据仓库·算法
HDU-Dade4 小时前
【校招笔试真题】简要介绍 Self-Attention 的前沿算法
人工智能·算法
小郎君6586 小时前
Vue keep-alive 切标签后滚动位置回顶?因为 onDeactivated 里读到的 scrollTop 是 0
算法
邵奈一6 小时前
GPT-6.1 Terra速度是Sol的3倍,价格减半
算法
RaaS1006 小时前
Node.js Brotli RCE 漏洞自查指南:fetch、undici、axios 都在影响面,三分钟确认你的版本
人工智能·深度学习·算法
shehuiyuelaiyuehao6 小时前
算法56,重排链表
数据结构·算法·链表
qq_452396237 小时前
第四篇:《索引原理与实战:B-tree、Hash、GIN、GiST、BRIN》
算法·哈希算法·gin
西索斯coding7 小时前
Qwen3-Max 与 Qwen-Plus:60 个真实修复任务评测方案
大数据·网络·算法·ai