UVA 7261 Xiongnu's Land

来源:互联网 发布:我的淘宝卖家旺旺号 编辑:程序博客网 时间:2024/06/08 07:57

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;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 门和墙有2cm缝隙怎么办 支座预埋钢板忘记埋了怎么办 做完线雕一边紧一边松怎么办 卖家把没发货的填写了单号怎么办 买的人民币白银亏了好多钱怎么办 带控制线的三相四线开关怎么办 覆膜除尘布袋风拉不动怎么办 家里装修把暖气管道打破了怎么办 冷水管与热水管接错了怎么办 磨砂皮的鞋子打湿变硬了怎么办 等离子淡化热处理层渗不够厚怎么办 寄快递快递公司把东西弄坏了怎么办 寄美国的快递客人拒绝清关怎么办 国际e邮宝几天没物流信息了怎么办 石家庄小学网上报名填错了怎么办 去医院看病不知道挂什么科怎么办 深水井深水泵埋了2米怎么办 请问我捡的手机不是我的指纹怎么办 宝宝把塑料子弹塞到了鼻子里怎么办 坐便池上面的小孔不出水怎么办 还没离职已经找好工作怎么办 因火车晚点而耽误下趟火车怎么办 在广州坐的士丢了东西怎么办 找兼职的话他要求交押金怎么办 08vip不给提现了怎么办 点击订阅号所收到内容字太大怎么办 我的小叶栀子花老是黄叶该怎么办? 联币金融倒闭了我投资的钱怎么办 新单位交养老保险不接收档案怎么办 高铁发车十小时没赶上怎么办 饿了么被阿里收购员工怎么办? 爱疯4s密码忘了怎么办 研究生论文盲审一直不出结果怎么办 查重报告有疑似剽窃观点怎么办 成绩考的不好怎么办读技校有用吗 孩子大学挂科太多家长应该怎么办 中专升大专的入学考没考上怎么办 小孩摔跤额头出了个包怎么办 小孩摔跤后脑勺出了个包怎么办 结婚后疏于关心老婆寒心了怎么办 江苏取消小高考高二学生怎么办