zoukankan      html  css  js  c++  java
  • hdu 3255 Farming

    http://acm.hdu.edu.cn/showproblem.php?pid=3255

    将种子的价值看做高度,即转化成若干个长方体的体积并

    枚举z轴,扫描线

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    
    using namespace std;
    
    #define N 30001
    
    typedef long long LL;
    
    int m,p[4];
    int X1[N],X2[N],Y1[N],Y2[N],s[N];
    
    int has[N<<1],tot;
    
    struct line
    {
        int xl,xr,h,f;
    }e[N<<1];
    
    int sum[N<<3],col[N<<3];
    
    void read(int &x)
    {
        x=0; int f=1; char c=getchar();
        while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
        while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
        if(f<0) x=-x;
    }
    
    bool cmp(line p,line q)
    {
        return p.h<q.h;
    }
    
    void up(int k,int l,int r)
    {
        if(col[k]) sum[k]=has[r+1]-has[l];
        else if(l==r) sum[k]=0;
        else sum[k]=sum[k<<1]+sum[k<<1|1];
    }
        
    void change(int k,int l,int r,int opl,int opr,int ty)
    {
        if(l>=opl && r<=opr)
        {
            col[k]+=ty;
            up(k,l,r);
            return;
        }
        int mid=l+r>>1;
        if(opl<=mid) change(k<<1,l,mid,opl,opr,ty);
        if(opr>mid) change(k<<1|1,mid+1,r,opl,opr,ty);
        up(k,l,r);
    }
            
    
    int main()
    {
        int T,n,u,d,tot,g;
        LL ans;
        read(T);
        for(int t=1;t<=T;++t)
        {
            read(n); read(m);
            for(int i=1;i<=m;++i) scanf("%d",&p[i]);
            tot=0;
            for(int i=1;i<=n;++i)
            {
                scanf("%d%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i],&s[i]);
                has[++tot]=Y1[i];
                has[++tot]=Y2[i];
                s[i]=p[s[i]];
            }
            sort(has+1,has+tot+1);
            tot=unique(has+1,has+tot+1)-has-1;
            sort(p+1,p+m+1);
            m=unique(p+1,p+m+1)-p-1; 
            ans=0;
            for(int j=1;j<=m;++j)
            {
                g=0;
                for(int i=1;i<=n;++i)
                    if(s[i]>=p[j])
                    {    
                        u=++g;
                        d=++g;
                        e[u].xl=lower_bound(has+1,has+tot+1,Y1[i])-has;
                        e[u].xr=lower_bound(has+1,has+tot+1,Y2[i])-has-1;
                        e[u].h=X1[i];
                        e[u].f=1;
                        e[d].xl=e[u].xl;
                        e[d].xr=e[u].xr;
                        e[d].h=X2[i];
                        e[d].f=-1;
                    }
                sort(e+1,e+g+1,cmp);
                for(int i=1;i<=g;++i)
                {
                    change(1,1,tot,e[i].xl,e[i].xr,e[i].f);
                    ans+=1LL*sum[1]*(p[j]-p[j-1])*(e[i+1].h-e[i].h);
                }
            }
            printf("Case %d: %lld
    ",t,ans);
        }
        return 0;
    }

    Farming

    Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 2188    Accepted Submission(s): 694


    Problem Description
    You have a big farm, and you want to grow vegetables in it. You're too lazy to seed the seeds yourself, so you've hired n people to do the job for you.
    Each person works in a rectangular piece of land, seeding one seed in one unit square. The working areas of different people may overlap, so one unit square can be seeded several times. However, due to limited space, different seeds in one square fight each other -- finally, the most powerful seed wins. If there are several "most powerful" seeds, one of them win (it does not matter which one wins).

    There are m kinds of seeds. Different seeds grow up into different vegetables and sells for different prices.
    As a rule, more powerful seeds always grow up into more expensive vegetables.
    Your task is to calculate how much money will you get, by selling all the vegetables in the whole farm.
     
    Input
    The first line contains a single integer T (T <= 10), the number of test cases.
    Each case begins with two integers n, m (1 <= n <= 30000, 1 <= m <= 3).
    The next line contains m distinct positive integers pi (1 <= pi <= 100), the prices of each kind of vegetable.
    The vegetables (and their corresponding seeds) are numbered 1 to m in the order they appear in the input.
    Each of the following n lines contains five integers x1, y1, x2, y2, s, indicating a working seeded a rectangular area with lower-left corner (x1,y1), upper-right corner (x2,y2), with the s-th kind of seed.
    All of x1, y1, x2, y2 will be no larger than 106 in their absolute values.
     
    Output
    For each test case, print the case number and your final income.
     
    Sample Input
    2 1 1 25 0 0 10 10 1 2 2 5 2 0 0 2 1 1 1 0 3 2 2
     
    Sample Output
    Case 1: 2500 Case 2: 16
     
    Source
     
  • 相关阅读:
    Dubbo的使用入门
    Centos7安装Tomcat并部署DubboAdmin的War包并配置自动启动
    JPA中自动使用@Table(name = "userTab")后自动将表名、列名添加了下划线的问题
    JAVA和C#检测IP地址段是否交叉和获取地址段IP列表的方法
    MySQL中的insert ignore into, replace into用法总结
    SpringBootWEB项目和非Web项目的全局异常捕获
    SpringBoot中配置起动时的数据库初始化角本
    树莓派中编译Opencv3.4.1和OpenCVSharp库
    树莓派简单摄像头录像并保存视频文件
    树莓派中编译OpenCV3.4.1和OpenCvSharp
  • 原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/12203490.html
Copyright © 2011-2022 走看看