poj 2398 Toy Storage 【二分】


点击打开链接



题意 :

            给你个箱子,然后n个隔板把箱子分成 n+1各区域。

            然后给你最后玩具的具体位置坐标。而且保证玩具不会在隔板上也不会在箱子外面。

            个上一题的区别是这次问你放了多少个玩具的区间分别是多少个。




题解:

          和上题一样,加个标记数组就可以了,






#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define x first
#define y second
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
const int maxn=5005;
int n,m,x1,y1,x2,y2,t1,t2;
pair<int,int> p[maxn];
int v[maxn];
bool cmp(pair<int,int> a,pair<int,int> b){
    return a.x<b.x;
}
int judge(int t,int a,int b){
    if(p[t].x==p[t].y){
        return a>=p[t].y;
    }else {
        int ret=(a-p[t].x)*(y2-y1)-(b-y1)*(p[t].y-p[t].x);
        return ret<0;
    }
}
int ans[maxn];
int main(){
    while(scanf("%d",&n)&&n){
        memset(v,0,sizeof(v));
        memset(ans,0,sizeof(ans));
        scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2);
        for(int i=1;i<=n;++i)
            scanf("%d %d",&p[i].x,&p[i].y);
        sort(p+1,p+1+n,cmp);
        p[0].x=p[0].y=min(x1,y1);
        p[n+1].x=p[n+1].y=max(x2,y2);
        for(int i=1;i<=m;++i){
            scanf("%d %d",&t1,&t2);
            int l=0,r=n+1;
            while(l<=r){
                int mid=(l+r)/2;
                if(judge(mid,t1,t2)) l=mid+1;
                else r=mid-1;
            }
            v[l-1]++;
        }
        int cnt=0;
        puts("Box");
        for(int i=0;i<=n;++i) if(v[i]) ans[v[i]]++;
        for(int i=0;i<maxn;++i) if(ans[i]) printf("%d: %d\n",i,ans[i]);
        //puts("");
    }

	return 0;
}





 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值