zoukankan      html  css  js  c++  java
  • HDU 6012【离散化+扫描线】

    Lotus and Horticulture

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 698    Accepted Submission(s): 224


    Problem Description
    These days Lotus is interested in cultivating potted plants, so she wants to build a greenhouse to meet her research desires.

    Lotus placed all of the n pots in the new greenhouse, so all potted plants were in the same environment.

    Each plant has an optimal growth temperature range of [l,r], which grows best at this temperature range, but does not necessarily provide the best research value (Lotus thinks that researching poorly developed potted plants are also of great research value).

    Lotus has carried out a number of experiments and found that if the growth temperature of the i-th plant is suitable, it can provide ai units of research value; if the growth temperature exceeds the upper limit of the suitable temperature, it can provide the bi units of research value; temperatures below the lower limit of the appropriate temperature, can provide ci units of research value.

    Now, through experimentation, Lotus has known the appropriate growth temperature range for each plant, and the values of a, b, c are also known. You need to choose a temperature for the greenhouse based on these information, providing Lotus with the maximum research value.

    __NOTICE: the temperature can be any real number.__
     
    Input
    The input includes multiple test cases. The first line contains a single integer T, the number of test cases.

    The first line of each test case contains a single integer n[1,50000], the number of potted plants.

    The next n line, each line contains five integers li,ri,ai,bi,ci[1,109].
     
    Output
    For each test case, print one line of one single integer presenting the answer.
     
    Sample Input
    1 5 5 8 16 20 12 10 16 3 13 13 8 11 13 1 11 7 9 6 17 5 2 11 20 8 5
     
    Sample Output
    83
     

    题意:

    n个区间 [)前闭后开型,每个区间左中右分别三个花费,问哪个点花费最大。

    题解:

    因为点可以取任意实数,区间是整数,所以距离区间端点0.5的点都是可能的点,将区间左右端点*2,每个区间离散化成 l-1, l, r这三个点。然后扫描线去遍历,碰到左边边界 +a-c; 右边界 +b-a;

    代码:

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <bitset>
     6 #include <vector>
     7 #include <queue>
     8 #include <stack>
     9 #include <cmath>
    10 #include <list>
    11 #include <set>
    12 #include <map>
    13 #define rep(i,a,b) for(int i = a;i <= b;++ i)
    14 #define per(i,a,b) for(int i = a;i >= b;-- i)
    15 #define mem(a,b) memset((a),(b),sizeof((a)))
    16 #define FIN freopen("in.txt","r",stdin)
    17 #define FOUT freopen("out.txt","w",stdout)
    18 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
    19 #define mid ((l+r)>>1)
    20 #define ls (id<<1)
    21 #define rs ((id<<1)|1)
    22 #define N 50005
    23 #define INF 0x3f3f3f3f
    24 #define INFF ((1LL<<62)-1)
    25 typedef long long LL;
    26 using namespace std;
    27 
    28 int T, n, HASH[N*3], l[N], r[N], a[N], b[N], c[N];
    29 LL cost[N*3];
    30 int main()
    31 {IO;
    32     //FIN;
    33     cin >> T;
    34     while(T--){
    35         cin >> n;
    36         int len = 0;
    37         LL tol = 0;
    38         rep(i, 1, n){
    39             cin >> l[i] >> r[i] >> a[i] >> b[i] >> c[i];
    40             l[i] <<= 1; r[i] <<= 1;
    41             HASH[len++] = l[i]; HASH[len++] = l[i]-1; HASH[len++] = r[i];
    42             tol += c[i];
    43         }
    44         sort(HASH, HASH+len);
    45         int size = unique(HASH, HASH+len)-HASH;
    46         LL ans = tol;
    47         mem(cost, 0);
    48         
    49         rep(i, 1, n){
    50             l[i] = lower_bound(HASH, HASH+size, l[i])-HASH;
    51             r[i] = lower_bound(HASH, HASH+size, r[i])-HASH;
    52             cost[l[i]] += a[i]-c[i];
    53             cost[r[i]+1] += b[i]-a[i];
    54         }
    55         rep(i, 0, size-1){
    56             tol += cost[i];
    57             ans = max(ans, tol);
    58         }
    59         cout << ans << endl;
    60     }
    61     return 0;
    62 }
    View Code
  • 相关阅读:
    ThinkPHP 3.2.3
    MobaXterm 可替代 XShell4 和 Xftp4
    SourceTree 合并DEV分支到master
    WOX 和 everything 差不多,挺不错也
    function 的入参 如果是指针的话,如果你用的好的话,会颠覆三观啊 这里就是指对象,数组不用考虑 // 夏娃的苹果
    buildFast.js node.js 快速发布到gitee上,这样就不用每次点击,并且自动弹出发布页面,再点击发布,完美!
    velocity.js
    【linux之sed及vim】
    linux curl命令详解
    哈夫曼(huffman)树和哈夫曼编码
  • 原文地址:https://www.cnblogs.com/Jstyle-continue/p/6375642.html
Copyright © 2011-2022 走看看