2015 Benelux Algorithm Programming Contest E-Excellent Engineers
2024-10-19 14:28:38
题目大意:有n个人,每个人都有三个物品,排名分别为a[ i ],b[ i ],b[ i ],现在要删掉其中的一些人
如果一个人x的三个物品的排名为a[ x ],b[ x ],b[ x ],若存在另一个人y物品排名为a[ y ],b[ y ],b[ y ],
且a[ y ]<a[ x ] && b[ y ]<b[ x ] && c[ y ]<c[ x ],则删掉x,问你最后剩下多少人。
思路:一开始肯定要按一个物品的排名进行排序,然后就三个人想了半小时没想出来,感觉要用数据
结构,但是不知道怎么写,看来还是对线段树不太了解!!!!
首先,我们按物品a的排名排序,然后我们用b物品的排名建立线段树维护物品c的最小值即可。
#include<bits/stdc++.h>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int N=1e5+;
const int inf=0x3f3f3f3f;
int mn[N<<],n;
struct node
{
int a,b,c;
bool operator <(const node &t)const
{
return a<t.a;
}
}w[N];
void updata(int x,int v,int l,int r,int rt)
{
if(l==r)
{
mn[rt]=min(mn[rt],v);
return;
}
int m=(l+r)>>;
if(x<=m) updata(x,v,lson);
else updata(x,v,rson);
mn[rt]=min(mn[rt<<],mn[rt<<|]);
}
int query(int L,int R,int l,int r,int rt)
{
if(l>=L && r<=R) return mn[rt];
int m=(l+r)>>;
int ans=inf;
if(L<=m) ans=min(ans,query(L,R,lson));
if(R>m) ans=min(ans,query(L,R,rson));
return ans;
}
int main()
{
int T; cin>>T;
while(T--)
{
cin>>n;
for(int i=;i<n;i++) scanf("%d%d%d",&w[i].a,&w[i].b,&w[i].c);
sort(w,w+n);
memset(mn,inf,sizeof(mn));
int ans=;
for(int i=;i<n;i++)
{
int g=query(,w[i].b,,n,);
if(g>w[i].c) ans++;
updata(w[i].b,w[i].c,,n,);
}
printf("%d\n",ans);
}
return ;
}
最新文章
- 2017年1月4日 星期三 --出埃及记 Exodus 21:30
- uvm - driver
- 如何运用boolean跳出循环
- Java 9终于要包含Jigsaw项目了
- android自定义activity
- 【C语言入门教程】1.1 基本程序结构
- String类中一些的方法的应用
- Knockout 新版应用开发教程之Observable Arrays
- WPF中ListView如何改变选中条背景颜色
- C#制作简易屏保(转)
- UnitOfWork实战
- Linux 基本命令-----常用操作分类
- 深度搜索DFS-Lake Counting(POJ NO.2386)
- Centos7源码安装mariadb
- p86商空间也是Banach空间
- setting.xml配置文件
- (原)android系统下绑定Server的时候报MainActivity has leaked ServiceConnection的错误
- android studio 引用远程仓库下载慢(JCenter下载慢)的办法
- 零开始:NetCore项目权限管理系统:登录授权
- Spring源码分析(三)容器核心类
热门文章
- webuploader
- mongoDB - 日常操作三
- Linux - 网络检测
- Redis 主从 keepalived高可用 实现 VIP 自动漂移
- CF1066D Boxes Packing
- org.apache.phoenix.exception.PhoenixIOException: SYSTEM:CATALOG
- JS浮点数运算Bug的解决办法
- 用conda管理Python包
- Libevent源码分析—event_add()
- python调用win32com.client的GetObject查找进程信息及服务信息