HDU5124 lines(贪心)

通俗讲解清楚光线追踪中的蒙特卡洛积分 彻底讲解光线追踪中的蒙特卡洛积分 阅读详情

lines

题目链接:

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

解题思路:

BestCoder官方题解:

我们可以将一条线段
  
   [xi,yi]
  分为两个端点
  
   xi
  和
  
   (yi)+1
  ,在
  
   xi
  时该点会新加入一条线段,同样的,在
  
   (yi)+1
  时该点会减少一条线段,因此对于2n个端点进行排序,令
  
   xi
  为价值1,
  
   yi
  为价值-1,问题转化成了最大区间和,因为1一定在-1之前,因此问题变成最大前缀和,我们寻找最大值就是答案,另外的,这题可以用离散化后线段树来做。复杂度为排序的复杂度即
  
   nlgn
  ,另外如果用第一种做法数组应是2n,而不是n,由于各种非确定性因素我在小数据就已经设了n=10W的点。
真忧桑,当时竟然把题目理解错了,看着许多人过了这道题,而自己却只能干瞪着眼,真郁闷。大哭大哭大哭

AC代码(vector):

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n,x;
        vector<pair<int,int> > v;
        scanf("%d",&n);
        for(int i = 0; i < n; i++){
            scanf("%d",&x);
            v.push_back(make_pair(x,1));
            scanf("%d",&x);
            v.push_back(make_pair(x+1,-1));
        }
        sort(v.begin(),v.end());
        int ans = 0,sum = 0,l = v.size();
        for(int i = 0; i < l; i++){
            sum += v[i].second;
            ans = max(sum,ans);
        }
        printf("%d\n",ans);
    }
    return 0;
}

AC代码(数组):

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

struct node{
  int x,p;
}no[200010];

bool cmp(node a,node b){
  return a.x < b.x;
}

int main(){
  int T;
  scanf("%d",&T);
  while(T--){
    int x,n;
    scanf("%d",&n);
    int ans = 0;
    for(int i = 0; i < n; i++){
      scanf("%d",&x);
      no[ans].x = x;
      no[ans++].p = 1;
      scanf("%d",&x);
      no[ans].x = x+1;
      no[ans++].p = -1;
    }
    sort(no,no+ans,cmp);
    int sum=0,cnt=0;
    for(int i = 0; i < ans;){
        int j=i;
        for(;no[j].x==no[i].x && j<ans;j++)
            sum += no[j].p;
        i = j;
        if(sum > cnt)
            cnt = sum;
        /*
        sum+=no[i].p;
        cnt=max(cnt,sum);
        这样写不行,因为sort排序,数组和vector还是有点区别的,自己敲敲代码,尝试一下就知道了
        */
    }
    printf("%d\n",cnt);
  }
  return 0;
}





物联网与人工智能项目实战:构建智能农业监控系统 智能农业监控系统通过物联网技术实时监测农业环境中的各项数据(如土壤湿度、温度、光照强度等),并利用人工智能技术分析和预测农业生产的趋势,进而为农民提供决策支持。系统的核心目标是提高农作物的产量和品质,同时减少资源浪费,优化农田管理。环境监测:实时采集农田的温湿度、土壤湿度、光照等环境数据。作物生长监测:通过传感器和图像识别技术监测作物的生长状况。智能灌溉系统:根据土壤湿度和气候条件自动调整灌溉量。病虫害检测与预警:利用人工智能和图像识别技术自动检测作物病虫害,并及时给出预警。数据分析与决策支持。 阅读详情

相关推荐

别再手动查日志了!用Dify+Zabbix打造你的专属运维“嘴替”(保姆级配置流程)

本文详细介绍了如何利用Dify平台与Zabbix监控系统集成,构建智能运维对话系统,实现自然语言交互的运维管理。通过保姆级配置流程,帮助运维工程师提升查询效率、降低学习成本,打造企业级智能运维解决方案。

weixin_27298377的博客 460

hdu 5124 lines (线段树+离散化)

lines Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 620    Accepted Submission(s): 288 Problem Description John has several lines

Coding A World 1034

HC-05蓝牙模块详细配置、连接与使用过程

用手按着模块上的按键,再给蓝牙模块上电。当蓝牙模块上的灯慢闪的时候就说明进入了配置模式了。在配置蓝牙的时候一定要将串口助手按这个要求配置:设置波特率 38400,数据位 8 位,停止位 1 位,无校验位,这是固定操作! 根据蓝牙的主从模式进行不同的设置,二者主要区别就在于AT+ROLE这个指令如果这里没返回OK可能有一下几种情况:如果正常返回OK,那就可以进行下一步了 配置蓝牙密码的时候,特别是配置HC05,密码必须加双引号"",否则不能正常设置!!!! 给从机模式蓝牙配置好之后,将蓝牙重

qq_51688022的博客 2万+

hdu 5124(区间更新+单点求值+离散化)

lines Time Limit: 5000/2500 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1575Accepted Submission(s): 656 Problem Description John has several lines. The l...

weixin_30517001的博客 136

华为昇腾310P3+deepseek蒸馏版性能调优:FP16精度优化全记录

本文详细介绍了在华为昇腾310P3硬件环境下优化DeepSeek蒸馏版模型FP16精度的关键技术路径。通过分层量化策略、内存分配优化和并行计算配置,显著提升模型推理性能,实现83%的并发处理能力提升,同时保持98.7%的原始模型准确率。

weixin_29074409的博客 356

tkinter表格进阶:5分钟实现CSV数据可视化编辑界面(含右键菜单配置)

本文详细介绍了如何使用Python的tkintertable库快速构建CSV数据可视化编辑界面。通过导入导出CSV数据、深度定制右键菜单(如复制、插入行、删除行)以及实现单元格验证等进阶功能,开发者能在5分钟内创建一个可嵌入自动化流程的专业级桌面数据编辑工具,显著提升数据处理效率。

933

HDU5124:lines(线段树+离散化)或(离散化思想)

http://acm.hdu.edu.cn/showproblem.php?pid=5124 Problem Description John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to kno...

weixin_33872660的博客 152

AI 辅助代码审查:开启代码质量管控的智能时代

AI辅助代码审查正在改变传统的代码质量管控方式。通过自动化分析、智能反馈和上下文感知,AI不仅提高了代码审查的效率,还提升了代码质量的一致性和可维护性。随着机器学习和深度学习技术的不断发展,未来AI将成为开发者日常工作中强大的助手,进一步推动软件开发向智能化、自动化方向发展。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 3235

hdu 5124——lines

题意:有一些线段覆盖一条一线,找出一个点,覆盖它的线段最多。求个数 思路:要找的这个点可能有无数多个,但是,给出的这些线段的端点一定有一个或者几个满足条件的。所以将给出的线段的端点记下,然后排序。用线段树维护区间内被覆盖次数的最大值。 错误:比赛的时候每用线段树想偷懒,结果只过了pretest。后来线段树初始化的时候,初始化的个数应当是按照不同端点的个数来,而不是线段的个数来,又错了好多次。

char256 568

【华为OD技术面-手撕算法代码真题】- 最长公共前缀

🌟 强烈推荐:华为OD技术面试手撕算法代码真题 🌟大家好!今天我给大家推荐一份备受赞誉的华为OD技术面试手撕算法代码真题。所有题目均为华为od实际面试过程中出现的算法代码真题。

算法大师! 4895

Flow Matching05:概率路径与插值【概率路径:线性插值路径(最简单)、高斯插值路径】【先尝试线性插值,看效果如何;若不够好,尝试高斯插值】

好的,我将从数学角度详细解释Flow Matching,从高中生能理解的基础知识开始,逐步深入到高级概念。

u013250861的博客 179

HDU - lines (树状数组&&离散化)

HDU - lines (树状数组&&离散化)

m0_73935863的博客 181

QGIS安装与使用教程

QGIS安装与使用教程

weixin_46713695的博客 2万+

hdu 5124 lines(贪心)

题目链接:hdu 5124 lines #include #include #include #include using namespace std; typedef pair pii; int N; vector vec; int main () { int cas, x, y; scanf("%d", &cas); while (cas--) { scanf

不慌不忙、不急不躁 821

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

HDU5124lines题解-堆+贪心的一个新方法

题目链接 https://cn.vjudge.net/problem/HDU-5124 胡扯 感觉说新方法好像有点不太好,但是翻了十几篇博客都是清一色离散化之类的... 为什么会做这道题呢?因为前几天做了套NOIp模拟赛,T1是坐标轴上的最大团,愉快地转化成最多不相交区间问题贪心处理 但是我把大于等于号看反了,以为区间相交才连边,于是转化成了"让你找出被覆盖次数最多的点(线段)被覆盖的次数",也就...

weixin_30872867的博客 232

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU 5124 lines

lines Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1439    Accepted Submission(s): 594 Problem Description John has several line

dml_96的博客 365

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

hdu5124 lines (输入输出挂写的)

lines Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description John has several lines. The lines are covered on the X axs. Let A is a point which is

jk13171217的专栏 871

HDU 5124

map优先队列#include<stdio.h> #include<iostream> #include<algorithm> #include<math.h> #include<string.h> #include<map> #include<queue> using namespac...

144

hdu5124(树状数组+离散化)

John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A. Input The first line contains a single in...

qq_40859951的博客 266

【HDU】5124 转换为最大前缀 或者 离散化线段树/树状数组

  ohn has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A. Input The first line contains a single i...

胖亚亚的小酒馆 265

hdu5124——lines

lines Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 330    Accepted Submission(s): 155 Problem Description John has several lines. Th

Alex 930

hdu 5124

hdu 5124 这个题还是比较水的,记篇博客是因为解题思路比较好。 题意: n条线段覆盖,问被覆盖最多的点是被多少条线段覆盖。 思路: 1)离散化+树状数组(O(nlogn)) 树状数组可由单点修改区间查询改为区间修改单点查询,因为树状数组求和是求二进制前缀和,所以如果是在区间[l,r]增加d,可以add(l,d),add(r + 1,-d),因为更新是更新后缀,而求和是求前缀和,所

AngelBeats! 617

智能积木入门:从传感器原理到编程避障车的完整实战指南

在机器人教育与STEAM实践持续升温的背景下,如何让初学者快速理解智能硬件的核心逻辑,成为许多家长与老师关注的焦点。智能积木作为一种低门槛的物理计算平台,将主控模块、传感器、电机与图形化编程融为一体,帮助用户在搭建中建立工程思维。通过红外距离传感器感知环境、颜色传感器识别路径、倾斜传感器读取姿态,配合条件判断与循环逻辑,即可实现避障、循线等经典机器人行为。本文从硬件拆解出发,介绍主控与传感器的原理与选型思路,并结合避障巡逻车的搭建实例,展示结构刚性设计、电机调试与参数优化方法,同时探讨循线小车、智能门闸等扩

weixin_33769125的博客 320

hdu 5124 lines【转化为区间和】

John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A. Input The first line contains a single in...

Sean 536

【瞎搞】HDU 5124 lines

点击打开链接 题意:给出n条线段求覆盖点 次数最多的条数。 #include #include #include #include #include #include #include #include using namespace std; #include #include #include #include #include #include #de

Kewowlo 600

【HDU】5124lines(二分+树状数组+离散化处理)

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2047    Accepted Submission(s): 893   Problem Description John has several lines. ...

红点雷龙XL 298
上一篇: HDU5123 who is the best?
下一篇: HDU 5112 A Curious Matt
yphacker
博客等级 码龄12年 199粉丝 540原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值