poj 2528 Mayor's posters

题目链接:http://poj.org/problem?id=2528

题目大意:求最终有多少张海报可见。

题目思路:最近想写一下矩形切割,当然,对于这道题不是很适合,不过可以过。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<queue>
#include<algorithm>
#include<vector>
#include<stack>
#include<list>
#include<iostream>
#include<map>
#include<math.h>
using namespace std;
#define inf 0x3f3f3f3f
#define uint unsigned __int64
#define M 1000000
struct node
{
        int p1,p2,co;
}a[M],now;
int used[10100],total;
int judge(node a,node b)
{
        if(a.p2<b.p1||a.p1>b.p2)
                return 0;
        else return 1;
}
void cut(node tmp)
{
        int k1,k2;
        k1=max(tmp.p1,now.p1);
        k2=min(tmp.p2,now.p2);
        if(tmp.p1<k1)
        {
                a[++total]=tmp;
                a[total].p2=k1-1;
        }
        if(tmp.p2>k2)
        {
                a[++total]=tmp;
                a[total].p1=k2+1;
        }
}
int main()
{
        int t,i,j,l,r,n;
        scanf("%d",&t);
        while(t--)
        {
                scanf("%d",&n);
                total=0;
                for(i=1;i<=n;i++)
                {
                        scanf("%d%d",&l,&r);
                        now.p1=l;now.p2=r;now.co=i;
                        for(j=total;j>=1;j--)
                        {
                                if(judge(now,a[j]))
                                {
                                        cut(a[j]);
                                        a[j]=a[total--];
                                }
                        }
                        a[++total]=now;
                }
                memset(used,0,sizeof(used));
                int num=0;
                for(i=1;i<=total;i++)
                {
                        if(!used[a[i].co])
                        {
                                used[a[i].co]=1;
                                num++;
                        }
                }
                printf("%d\n",num);
        }
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值