zoukankan      html  css  js  c++  java
  • HDU 3634 City Planning (离散化)

    City Planning

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 483    Accepted Submission(s): 203


    Problem Description
    After many years, the buildings in HDU has become very old. It need to rebuild the buildings now. So Mr dragon (the president of HDU's logistics department ) ask Mr Wan (a very famous engineer) for help.
    Mr Wan only draw one building on a construction design drawings(all the buildings are rectangle and each edge of buildings' is paraller or perpendicular to others buildings' edge ). And total draw n drawings (all the drawings have same width and length . And bottomleft point is (0, 0)). Due to possible overlap of conditions, so when they build a new building, they should to remove all the overlapping part of it. And for each building, HDU have a jury evaluate the value per unit area. Now Mr dragon want to know how to arrange the order of build these buildings can make the highest value.
     
    Input
    The first line of input is a number T which indicate the number of cases . (1 < T < 3000);
    Each test case will begin with a single line containing a single integer n (where 1 <= n <= 20). 
    Next n line will contain five integers x1, y1, x2, y2 ,value . x1,y1 is bottomleft point and x2,y2 is topright point , value is the value of the buildings' unit area.((0 <= x1, y1, x2, y2 <= 10000) (x1 < x2, && y1 < y2) (1 <= value <= 22)
     
    Output
    For each case. You just ouput the highest value in one line.
     
    Sample Input
    1 3 1 1 10 10 4 4 4 15 5 5 7 8 20 30 6
     
    Sample Output
    Case 1: 2047
     
    Author
    08052233
    感慨:啊啊啊,英语不好啊,overlap这个单词不知道。
    题意:求面积最大价值。每个矩形都有对应价值,如果有相交,则新的矩形将覆盖旧的矩形那块面积。
    收获:离散化。将坐标离散化。注意精度问题。
    #include <cstdio>
    #include <iostream>
    #include <cstdlib>
    #include <algorithm>
    #include <ctime>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <stack>
    #include <queue>
    #include <list>
    #include <vector>
    #include <map>
    #include <set>
    using namespace std;
    
    const int INF=0x3f3f3f3f;
    const double eps=1e-10;
    const double PI=acos(-1.0);
    #define maxn 50
    struct Rect
    {
        int x1, x2, y1, y2, val;
        bool operator < (const Rect &r) const{
            return val < r.val;
        }
    };
    Rect r[maxn];
    int val[maxn][maxn];
    int x[maxn], y[maxn];
    int main()
    {
        int t, n;
        int cas = 0;
        scanf("%d", &t);
        while(t--)
        {
            scanf("%d", &n);
            int cnt = 0 ;
            for(int i = 0; i < n; i++,cnt+=2)
            {
                scanf("%d%d%d%d%d", &r[i].x1, &r[i].y1, &r[i].x2, &r[i].y2, &r[i].val);
                x[cnt] = r[i].x1; x[cnt+1] = r[i].x2;
                y[cnt] = r[i].y1; y[cnt+1] = r[i].y2;
            }
            sort(r, r + n);
            sort(x, x + cnt);
            sort(y, y + cnt);
            memset(val, 0, sizeof val);
            for(int i = 0; i < n; i++)
            {
                int x1 = lower_bound(x, x + cnt, r[i].x1) - x;
                int x2 = lower_bound(x, x + cnt, r[i].x2) - x;
                int y1 = lower_bound(y, y + cnt, r[i].y1) - y;
                int y2 = lower_bound(y, y + cnt, r[i].y2) - y;
                //printf("%d %d %d %d
    ", x1, x2, y1, y2);
                for(int j = x1; j < x2; j++)
                    for(int k = y1; k < y2; k++)//将一个大矩形,分成一个一个小矩形。
                        val[j][k] = r[i].val;
            }
            long long ans = 0;
            for(int i = 0; i < cnt-1; i++)
                for(int j = 0; j < cnt-1; j++)
                    ans +=(long long) val[i][j]*(x[i+1] - x[i]) *(y[j+1] - y[j]);
             printf("Case %d: %I64d
    ", ++cas, ans);
        }
        return 0;
    }
     
  • 相关阅读:
    2017-2018-1 20179226 《文献管理与信息分析》第1讲学习总结
    2017-2018-1 20179226《Linux内核原理与分析》第十一周作业
    2017-2018-1 20179226《Linux内核原理与分析》第十周作业
    2017-2018-1 20179226 《从问题到程序》第2周学习总结
    2017-2018-1 20179226 《构建之法》第1周学习总结
    掌握一种编辑器-Vim
    2017-2018-1 20179226 《深入理解计算机系统》第1周学习总结
    2017-2018-1 20179209《Linux内核原理与分析》第二周作业
    20179209《Linux内核原理与分析》第一周作业
    linux_cpu信息查询
  • 原文地址:https://www.cnblogs.com/ZP-Better/p/4734380.html
Copyright © 2011-2022 走看看