hdu 2795 Billboard

Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11194    Accepted Submission(s): 4944


Problem Description
At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes in the dining room menu, and other important information.
在大学的入口,那里有一个巨大的矩形告示牌,长宽比为h*w。基本上那个告示牌上啥都有,最近的编程比赛啦,食堂的菜单变化啦,和其他的重要信息
On September 1, the billboard was empty. One by one, the announcements started being put on the billboard.
在九月一号,板子是空的。然后板子上开始一个又一个的贴告示。
Each announcement is a stripe of paper of unit height. More specifically, the i-th announcement is a rectangle of size 1 * wi.
每个告示是一个单位高度的条形告示。更具体来讲,第i个告示是一个大小为1*wi的矩形。
When someone puts a new announcement on the billboard, she would always choose the topmost possible position for the announcement. Among all possible topmost positions she would always choose the leftmost one.
当有人想要在板子上面张贴一个新告示,她会选一个最高的位置来张贴。在最高的可以张贴的位置那,她会选一个最靠左面的位置。
If there is no valid location for a new announcement, it is not put on the billboard (that's why some programming contests have no participants from this university).
如果那里已经没有空的位置可以张贴告示,就不会往板子上面贴告示了(这就是为什么很多程序竞赛没人参加)
Given the sizes of the billboard and the announcements, your task is to find the numbers of rows in which the announcements are placed.
给出板子的大小和告示,你的任务去找到张贴告示的行数
 

Input
There are multiple cases (no more than 40 cases).
那里有几组数据,不会超过40个
The first line of the input file contains three integer numbers, h, w, and n (1 <= h,w <= 10^9; 1 <= n <= 200,000) - the dimensions of the billboard and the number of announcements.
输入的第一行包括三个数字h,w,n (1 <= h,w <= 10^9; 1 <= n <= 200,000) ,板子的尺寸,和告示的数量。
Each of the next n lines contains an integer number wi (1 <= wi <= 10^9) - the width of i-th announcement.
接下来n行每行一个整数wi  (1 <= wi <= 10^9),第i个告示的宽度
 

Output
For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't be put on the billboard, output "-1" for this announcement.
对于每个告示输出一个数字,代表这个告示挂在了第几行,行就是一个数字从1到h,从最高的那一行开始算。如果这个告示张贴不了,输出-1。
 

Sample Input
  
3 5 5 2 4 3 3 3
 

Sample Output
  
1 2 1 3 -1
 

Author
hhanger@zju
 

Source
 

Recommend
lcy

线段树练习里面的题目,对点的更新,打眼一看是二维的,做的时候就是每个节点作为一个宽度,然后每次插进来一个节点就减去这个节点的长度,然后根节点保存宽度剩下最大的那个线段。。。
#include <stdio.h>
#include <string.h>
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1

const int maxn = 222222;
int MAX[maxn << 2];
int h, n, w;

int max(int a, int b){
    return a > b ? a : b;
}

void PushUp(int rt){
    MAX[rt] = max(MAX[rt << 1], MAX[rt << 1 | 1]);
}

void build(int l, int r, int rt){
    int m;
    MAX[rt] = w;
    if (l == r)
        return;
    m = (l + r) >> 1;
    build(lson);
    build(rson);
    PushUp(rt);
}

int query(int x, int l, int r, int rt){
    int m, ret = 0;

    if (l == r){
        MAX[rt] -= x;
        return l;
    }
    m = (l + r) >> 1;
    
    if (x <= MAX[rt << 1]){
        ret = query(x, lson);
    }else ret = query(x, rson);
    PushUp(rt);

    return ret;
    
}
int main(void){

    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int i, x;
    while(scanf("%d%d%d", &h, &w, &n) != EOF){
        if (h > n)
            h = n;
        build(1, h, 1);
        for (i = 0;i < n;i ++){
            scanf("%d", &x);
            if (x > MAX[1])
                printf("-1\n");
            else printf("%d\n", query(x, 1, h, 1));
        }
    }
    return 0;
}


内容概要:本文详细介绍了“秒杀商城”微服务架构的设计与实战全过程,涵盖系统从需求分析、服务拆分、技术选型到核心功能开发、分布式事务处理、容器化部署及监控链路追踪的完整流程。重点解决了高并发场景下的超卖问题,采用Redis预减库存、消息队列削峰、数据库乐观锁等手段保障数据一致性,并通过Nacos实现服务注册发现与配置管理,利用Seata处理跨服务分布式事务,结合RabbitMQ实现异步下单,提升系统吞吐能力。同时,项目支持Docker Compose快速部署和Kubernetes生产级编排,集成Sleuth+Zipkin链路追踪与Prometheus+Grafana监控体系,构建可观测性强的微服务系统。; 适合人群:具备Java基础和Spring Boot开发经验,熟悉微服务基本概念的中高级研发人员,尤其是希望深入理解高并发系统设计、分布式事务、服务治理等核心技术的开发者;适合工作2-5年、有志于转型微服务或提升架构能力的工程师; 使用场景及目标:①学习如何基于Spring Cloud Alibaba构建完整的微服务项目;②掌握秒杀场景下高并发、超卖控制、异步化、削峰填谷等关键技术方案;③实践分布式事务(Seata)、服务熔断降级、链路追踪、统一配置中心等企业级中间件的应用;④完成从本地开发到容器化部署的全流程落地; 阅读建议:建议按照文档提供的七个阶段循序渐进地动手实践,重点关注秒杀流程设计、服务间通信机制、分布式事务实现和系统性能优化部分,结合代码调试与监控工具深入理解各组件协作原理,真正掌握高并发微服务系统的构建能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值