UVA 7261 Xiongnu's Land

U can find the original link here

this question need us to find a line parallel to y axis that divide the given area of (0,0) to (R,R),witch satsifiy the two conditions:one is the part in left have more green land and make the difference between the two part as small as possible ,another is the left one has more always has more land the the one in the right

so we can scan the whole area to find a divide the green land space just in two ,and find if the line we find can expand .
question give us 1e6 parameter of R but only 1e4 greend land , we can search in the last one ,it’s a smart move

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e4+50;
typedef long long LL;
struct Node
{
    int l,r,h;
};
int t,R,n;
Node a[maxn];
LL cal(int x)
{
    LL sum=0;
    for(int i=0; i<n; i++)
        if(a[i].l<x)
            sum+=(LL)(min(a[i].r,x)-a[i].l)*a[i].h;
    return sum;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        LL sum=0;
        scanf("%d",&R);
        scanf("%d",&n);
        for(int i=0; i<n; i++)
        {
            int x,y,w,h;
            scanf("%d%d%d%d",&x,&y,&w,&h);
            a[i].l=x,a[i].r=x+w,a[i].h=h;
            sum+=(LL)w*h;
        }
        int l=0,r=R,mid;
        while(l<r)
        {
            mid=(l+r)/2;
            LL area=cal(mid);
            if(2*area<sum) l=mid+1;
            else r=mid;
        }
        LL tmp=cal(r);
        while(cal(r)==tmp&&r<=R) r++;
        printf("%d\n",r-1);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值