离散化处理+Mayor's posters
来源:互联网 发布:复制淘宝店铺违规吗 编辑:程序博客网 时间:2024/06/16 13:34
Mayor's posters
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 90 Accepted Submission(s) : 23
- Every candidate can place exactly one poster on the wall.
- All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown).
- The wall is divided into segments and the width of each segment is one byte.
- Each poster must completely cover a contiguous number of wall segments.
They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections.
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall.
151 42 68 103 47 10
4
#include<iostream>
#include<algorithm>
#include<stdio.h>
#define M 10010
using namespace std;
int x[M*8];
int lala[M*1000];
struct node2
{
int l;
int r;
}a[M*8];
struct node
{
int l;int r;int flag;
}tree[M*8];
void build(int id,int l,int r)
{
tree[id].l=l;
tree[id].r=r;
tree[id].flag=0;
if(l==r)
return;
int m=(l+r)/2;
build(id*2,l,m);
build(id*2+1,m+1,r);
}
int query(int id,int L,int R)
{
int result;
if(tree[id].flag!=0)//因为我是倒着来的,所以在最后涂的一定不会被遮盖,所以如果这个位置标记不为0,则说明有广告了,不能露出来,返回0
return 0;
if(tree[id].l==L&&tree[id].r==R)
{
tree[id].flag=1;//此处有颜色了,忘记改了
return 1;
}
int mid=(tree[id].l+tree[id].r)/2;
if(R<=mid)
result=query(id*2,L,R);
else if(L>mid)
result=query(id*2+1,L,R);
else
{
result=query(id*2,L,mid)|query(id*2+1,mid+1,R);(??????)
}
if(tree[id*2].flag!=0&&tree[id*2+1].flag!=0)
tree[id].flag=1;//孩子节点反馈父亲节点(这部分为什么不能省????)
return result;
}
int main()
{
int t,n;
cin>>t;
while(t--)
{
scanf("%d",&n);
int cnt=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].l,&a[i].r);
x[cnt++]=a[i].l;
x[cnt++]=a[i].r;
}
sort(x,x+cnt);
cnt=unique(x,x+cnt)-x;//消除相同的坐标
for(int i=0;i<cnt;i++)
{
lala[x[i]]=i;//此处很巧妙,记录了位置,与下呼应
}
build(1,0,cnt-1);
int ans=0;
for(int i=n-1;i>=0;i--)
{
if(query(1,lala[a[i].l],lala[a[i].r]))
ans++;
}
cout<<ans<<endl;
}
return 0;
}
- 离散化处理+Mayor's posters
- POJ Mayor's posters (线段树+离散化处理)
- 【线段树+离散化】Mayor's Posters
- 线段树+离散化Mayor's posters
- POJ2528--Mayor's posters(离散化)
- POJ 2528 Mayor's posters (线段树+离散化处理)
- soj 2249 Mayor's posters(带相邻处理的离散化 + 线段树)
- poj_2528 Mayor's posters(线段树染色+离散化处理)
- POJ 2528 Mayor’s posters (线段树+离散化处理) 彻底搞懂延迟标记
- 离散化+线段树 POJ 2528 (Mayor's posters)
- POJ 2528 Mayor's posters(离散化+线段树)
- poj 2528 Mayor's posters 离散化 线段树
- poj 2528 Mayor's posters 正确离散化
- pku 2528 Mayor's posters-线段树+离散化
- POJ 2528 Mayor's posters 线段树+离散化
- poj 2528 Mayor's posters 线段树+离散化
- POJ 2528 Mayor's posters (线段树+离散化)
- POJ 2528 Mayor's posters(离散化+线段树)
- Ros_9
- HBase namespace
- 设计模式——装饰者模式
- Python(5):Anaconda+Python3.6打包pyqt图形应用为EXE
- leetcode_3.Longest Substring Without Repeating Characters
- 离散化处理+Mayor's posters
- UVA11292 The Dragon of Loowater
- 600. Non-negative Integers without Consecutive Ones
- Serverless,后端小程序的未来(转载)
- 手敲排序&HqzSort
- C# Xp 兼容性问题集
- 小迪教程第三天——access注入片段
- Hadoop和Spark学习日记3
- markdown编辑器