zoukankan      html  css  js  c++  java
  • BZOJ 1537: [POI2005]Aut- The Bus(dp + BIT)

    对y坐标离散化, 然后按x坐标排序, dp. 一个点(x, y), 设到达这个点接到的最多乘客数为t, 那么t可以用来更新y'>=y的所有点.用树状数组维护最大值. 

    ---------------------------------------------------------------------------------

    #include<bits/stdc++.h>
     
    using namespace std;
     
    const int maxn = 100009;
     
    int N;
     
    #define lowbit(x) ((x) & -(x))
    struct BIT  {
    int b[maxn];
    BIT() {
    memset(b, 0, sizeof b);
    }
    inline void update(int p, int v) {
    for(; p <= N; p += lowbit(p))
       b[p] = max(b[p], v);
    }
    inline int query(int p) {
    int ret = 0;
    for(; p; p -= lowbit(p))
       ret = max(ret, b[p]);
    return ret;
    }
    } bit;
     
    struct stop {
    int x, y, w;
    inline void Read() {
    scanf("%d%d%d", &x, &y, &w);
    }
    bool operator < (const stop &o) const {
    return x < o.x || (x == o.x && y < o.y);
    }
    } A[maxn];
     
    int id[maxn];
     
    int main() {
    int n;
    for(int i = 0; i < 3; i++) scanf("%d", &n);
    for(int i = 0; i < n; i++) {
    A[i].Read();
    id[i] = A[i].y;
    }
    sort(id, id + n); N = unique(id, id + n) - id;
    sort(A, A + n);
    int ans = 0;
    for(int i = 0; i < n; i++) {
    int p = lower_bound(id, id + N, A[i].y) - id + 1;
    int t = A[i].w + bit.query(p);
    ans = max(t, ans);
    bit.update(p, t);
    }
    printf("%d ", ans);
    return 0;
    }

    --------------------------------------------------------------------------------- 

    1537: [POI2005]Aut- The Bus

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 210  Solved: 143
    [Submit][Status][Discuss]

    Description

    Byte City 的街道形成了一个标准的棋盘网络 – 他们要么是北南走向要么就是西东走向. 北南走向的路口从 1 到 n编号, 西东走向的路从1 到 m编号. 每个路口用两个数(i, j) 表示(1 <= i <= n, 1 <= j <= m). Byte City里有一条公交线, 在某一些路口设置了公交站点. 公交车从 (1, 1) 发车, 在(n, m)结束.公交车只能往北或往东走. 现在有一些乘客在某些站点等车. 公交车司机希望在路线中能接到尽量多的乘客.帮他想想怎么才能接到最多的乘客.

    Input

    第一行三个数n, m 和 k – 表示北南走向的路的个数以及西东走向的路和乘客等车的站点的个数. ( 1 <= n <= 10^9, 1 <= m <= 10^9, 1 <= k <= 10^5). 接下来k 行每行描述一个公交站的信息.第 i + 1 行三个正整数 xi, yi 和 pi, 1 <= xi <= n, 1 <= yi <= m, 1 <= pi <= 10^6. 表示在(xi, yi) 有 pi 个乘客在等车. 每个路口在数据中最多出现一次,乘客总数不会超过1 000 000 000.

    Output

    一个数表示最多能接到的乘客数量.

    Sample Input

    8 7 11
    4 3 4
    6 2 4
    2 3 2
    5 6 1
    2 5 2
    1 5 5
    2 1 1
    3 1 1
    7 7 1
    7 4 2
    8 6 2

    Sample Output

    11

    HINT

    Source

  • 相关阅读:
    hdu 6702 ^&^ 位运算
    hdu 6709 Fishing Master 贪心
    hdu 6704 K-th occurrence 二分 ST表 后缀数组 主席树
    hdu 1423 Greatest Common Increasing Subsequence 最长公共上升子序列 LCIS
    hdu 5909 Tree Cutting FWT
    luogu P1588 丢失的牛 宽搜
    luogu P1003 铺地毯
    luogu P1104 生日
    luogu P1094 纪念品分组
    luogu P1093 奖学金
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4725922.html
Copyright © 2011-2022 走看看