BZOJ 2731: [HNOI2012]三角形覆盖问题

VFK大爷太神辣%%%%%%%%

神犇就是厉害,从小就会暴力过题

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=10000+5;
struct tri{
	int x,y,d,l,r;
	bool operator < (const tri &rhs)const{
		return y<rhs.y;
	}
}t[N];
int pre[N],next[N];
void del(int x){
	pre[next[x]]=pre[x];
	next[pre[x]]=next[x];
}
void ins(int x,int y){
	pre[next[x]]=y;
	next[y]=next[x];
	pre[y]=x;
	next[x]=y;
}
int head,tail,nowh;
bool ins(int x){
	if(!t[x].d)return false;
	for(int i=next[head];i!=tail;i=next[i])
	if(t[i].x<=t[x].x&&t[x].x+t[x].d-1<=t[i].x+t[i].d-1-(t[i].d-nowh))return false;
	ins(head,x);
	return true;
}
int cover[N*100];
int main(){	
	//freopen("a.in","r",stdin);
	int n;scanf("%d",&n);
	int mx=0;
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&t[i].x,&t[i].y,&t[i].d);
		mx=max(mx,t[i].y+t[i].d);
		t[i].l=t[i].x;
		t[i].r=t[i].x+t[i].d-1;
	}
	sort(t+1,t+1+n);
	int ans=0;
	head=0;tail=n+1;
	pre[next[head]=tail]=head;
	int last=0,j=1;
	for(int i=t[1].y;i<=mx;i++){
		int now=last;
		for(int k=next[head];k!=tail;k=next[k]){
			cover[t[k].r]--;
			if(!cover[t[k].r])now--;
			t[k].r--;
			if(t[k].r<t[k].l)del(k);
		}
		ans+=now+last;
		while(j<=n&&t[j].y==i){
			if(ins(j)){
				for(int k=t[j].x;k<t[j].x+t[j].d;k++){
					if(!cover[k])now++;
					cover[k]++;
				}
			}
			j++;
		}
		last=now;
	}
	printf("%.1lf\n",double(ans)/2.0);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值