题目:http://poj.org/problem?id=1389 题意:给出n个矩形的左下角和右上角,求出所有矩形面积的并 思路:线段树+离散化+扫描线#include <stdio.h> #include <algorithm> #include <iostream> using namespace std; const int maxn=2000; struct SegMentTree { int l, r, cover, len, sum; }st[maxn<<2]; struct Line { int y_top, y_btm, x; int in; bool operator<(Line l) const { return x<l.x; } }l[maxn+10]; int y[maxn+10], ans, cnt; void BuildTree(int v, int left, int right) { st[v].l=left, st[v].r=right, st[v].cover=0, st[v].len=y[right]-y[left]; if (right-left==1) { st[v].sum=0; return; } int lc=v<<1; int rc=lc+1; int mid=(left+right)>>1; BuildTree(lc, left, mid); BuildTree(rc, mid, right); st[v].sum=st[lc].sum+st[rc].sum; } void Update(int x) { if (st[x].cover>0) st[x].sum=st[x].len; else if (st[x].r-st[x].l>1) st[x].sum=st[x*2].sum+st[x*2+1].sum; else st[x].sum=0; } void Insert(int v, int left, int right) { if (st[v].l==left&&st[v].r==right) st[v].cover++; else { int lc=v<<1; int rc=lc+1; int mid=(st[v].l+st[v].r)>>1; if (right<=mid) Insert(lc, left, right); else if (left>=mid) Insert(rc, left, right); else { Insert(lc, left, mid); Insert(rc, mid, right); } } Update(v); } void Delete(int v, int left, int right) { if (st[v].l==left&&st[v].r==right) st[v].cover--; else { int lc=v<<1; int rc=lc+1; int mid=(st[v].l+st[v].r)>>1; if (right<=mid) Delete(lc, left, right); else if (left>=mid) Delete(rc, left, right); else { Delete(lc, left, mid); Delete(rc, mid, right); } } Update(v); } int GetIndex(int x) { return lower_bound(y, y+cnt, x)-y; } int main() { //freopen("in.txt", "r", stdin); int x1, y1, x2, y2; while (scanf("%d %d %d %d", &x1, &y1, &x2, &y2)==4) { int i=0; if (x1==-1&&y1==-1&&x2==-1&&y2==-1) break; do { l[i*2].y_top=l[i*2+1].y_top=y1; l[i*2].y_btm=l[i*2+1].y_btm=y2; l[i*2].x=x1, l[i*2+1].x=x2; l[i*2].in=1, l[i*2+1].in=0; y[i*2]=y1, y[i*2+1]=y2; i++; }while (scanf("%d %d %d %d", &x1, &y1, &x2, &y2)&&(x1!=-1&&y1!=-1&&x2!=-1&&y2!=-1)); sort(y, y+2*i); sort(l, l+2*i); cnt=0; for (int j=1; j<2*i; j++) { if (y[j]!=y[j-1]) y[cnt++]=y[j-1]; } y[cnt++]=y[2*i-1]; BuildTree(1, 0, cnt-1); ans=0; for (int j=0; j<2*i-1; j++) { if (l[j].in) Insert(1, GetIndex(l[j].y_top), GetIndex(l[j].y_btm)); else Delete(1, GetIndex(l[j].y_top), GetIndex(l[j].y_btm)); ans+=(l[j+1].x-l[j].x)*st[1].sum; } printf("%d\n", ans); } }
相关推荐
2024 《计算机网络》实验教学指导书.doc
2024 《计算机网络》实验教学指导书.doc
POJ 1389 Area of Simple Polygons
Area of Simple Polygons Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged onPKU. Original ID:138964-bit integer IO format:%lld Java class name:Main There are N...
不平衡电网下自抗扰顺序模型预测PWM整流器控制仿真模型(Simulink仿真实现)
内容概要:本文围绕面向城市空中交通的多无人机路径规划问题展开研究,提出了一套融合全局规划、动态避障与局部协同调整的综合路径规划方法。研究内容涵盖基于改进RRT算法与图论的全局路径规划、基于动态风险场和动态窗口法(DWA)的模型预测控制实现动态避障,以及基于分布式协同控制的多无人机局部路径协同策略。通过Matlab平台构建仿真环境,在多种典型城市交通场景下对所提方法进行了系统性验证,结果表明该方法在路径安全性、编队稳定性与任务效率方面表现优异。文章还深入探讨了算法的创新点与未来研究方向,为复杂城市环境下多无人机系统的自主协同提供了理论支撑与技术路径。; 适合人群:具备自动化、控制理论、计算机科学或相关领域基础知识,从事无人机系统、智能交通、路径规划、多智能体协同控制等方向研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①为城市空中交通系统中的多无人机安全、高效飞行提供可靠的路径规划解决方案;②支持在复杂、动态的城市场景中开展无人机自主导航、编队飞行与协同控制的技术研究与仿真验证。; 阅读建议:建议结合提供的Matlab代码进行实践操作,重点关注算法的具体实现细节、参数配置对性能的影响以及不同仿真场景下的实验设计,以深入理解各模块的集成逻辑与实际应用效果。
PKU 2352 Stars
题目:http://poj.org/problem?id=2352 题意:平面上有n个星星,每个星星的等级是比该星星的X和Y坐标都小的星星的个数,给出每个星星的坐标(按y轴升序),输出等级0~n-1每个等级的星星个数。 思路:线段树,因为y轴升序给出,我们只考虑x轴就可以, 每次查询只需要查询0~x区间的个数即可。 #include #include const int maxn=320
Mamba再封神!与YOLO结合,拿下二区!好发不卷!
相比传统的YOLO改进,Mamba是新技术,两者结合尚在蓝海阶段,可发挥空间大!更为关键的是,它在检测精度和速度方面,都让以往的YOLO模型难以望其项背!比如代表模型Mamba YOLO,便在参数减少45.5%、FLOPs减少50%的同时,精度还比YOLOv8高6.1%!这主要得益于,Mamba能够捕捉长期依赖关系,而YOLO则擅长捕捉局部特征,两者能够优势互补,且Mamba线性复杂度的特性,也有利于提高计算效率!为了让大家能够紧跟前沿发展,找到更多灵感启发,我给大家10种。
【游戏开发】初识寻路&navmesh,探索RecastDemo
在手游时代,尤其对于大世界游戏而言,寻路的实现基本在专门的寻路服务器上进行。在众多寻路的解决方案中,recastnavigation是最为经典实用的一个,很多游戏甚至游戏引擎都采用类似的实现。recastnavigation项目自带了RecastDemo,用图形化的界面帮助用户认识寻路网格(navmesh)的生成以及寻路的过程。因此,作为初学者的笔者,也决定通过RecastDemo去初步认识寻路的机理奥秘。 构建RecastDemo 首先克隆recastnavigation项目,从文档中可以看到Recast
PKU 2104 K-th Number
题目:http://poj.org/problem?id=2104 借此题学习了一下划分树 划分树定义: 他的每个节点保存【l, r】区间的所有元素,元素的排列顺序与输入的顺序相同,但是其两个子树的元素是所有元素排序后, 有(l+r)/2个元素进入左子树,其余的进入右子树,同时 维护一个num[]变量, num[i]表示l->i中, 有多少个元素进入了左子树。 红色代表进入左子树的元素
Nginx/OpenResty目录穿越漏洞复现
Nginx/OpenResty目录穿越漏洞复现 漏洞背景: 2020年03月18日, 360CERT监测发现 openwall oss-security 邮件组披露了两枚漏洞。在特定配置下 nginx/openresty 存在 内存泄漏漏洞/目录穿越漏洞。 Nginx 是异步框架的网页服务器,也可以用作反向代理、负载平衡器和HTTP缓存。 OpenResty是一个基于nginx的Web平台,它对nginx增加LuaJIT引擎使其运行Lua脚本。 影响版本: nginx <= v1.17
PKU 2063 Investment
题目:http://poj.org/problem?id=2063 题意:Jone 有M钱,有d种股票,给出每种股票的价值和年利息,给你y年的时间,使你的钱最多。 思路:典型的完全背包,可以参见背包九讲,需要注意的是The value of a bond is always a multiple of $1000,就是股票的价值是1000的倍数,这样就可以降低 时间复杂度了。。。。
Globus 数据下载
Globus 大数据下载流程~
Win10无外网热点搭建全指南:纯局域网通信与设备互联
热点并不是只有共享上网一种用途。在很多工程与办公场景中,我们需要的是让手机、笔记本、开发板等设备临时组成一个纯内网,完成文件传输、端口调试或局域网联机,而不需要任何外网出口。Win10笔记本在不连接互联网的状态下,借助系统移动热点或netsh承载网络,完全可以创建一个无外网热点,实现设备间二层互通。其核心在于利用SoftAP建立虚拟无线接入点,并绕开或禁用ICS的NAT转发。掌握这一技术,可在会议、出差、物联网调试等场景中快速搭建临时局域网,无需额外路由器。本文详细梳理三种实现路径、操作步骤及常见故障排查,
PKU 2947 Widget Factory
题目:http://poj.org/problem?id=2947 题意:工人生产不同的部件需要不同的时间,最少需要3天,最多需要9天。 现有给出n种部件和m条记录,每条记录包括该工人生产部件的总数k和他开始生产时间和结束时间(只给出是周几,不给出具体时间),之后给出这K个部件跟别所属的种类。 最后求出生产这n种部件分别所需要的时间。 思路:高斯消元,设每种部件生产一个所需
MATLAB实战:利用扫频数据重构系统伯德图的关键步骤
本文详细介绍了如何利用MATLAB处理扫频数据并重构系统伯德图的完整实战流程。内容涵盖数据导入与清洗、增益与相位的精确计算、频率响应数据对象(frd)的构建、数据平滑与插值处理,以及最终生成专业伯德图并进行关键参数(如相位裕度)标注的方法。文章重点解决了从实测“黑盒子”系统数据出发,获取直观频率响应特性曲线的核心问题,为控制系统分析与设计提供了实用指南。
PKU 1014 Dividing
题目:http://poj.org/problem?id=1014 题意:有6个物品,价值分别为1、2、3、4、5、6,输入6个数,代表相应的物品的个数,问的是 能不能物品分成两份,每份的价值总和相同。 思路:深搜或多重背包~~~ 好久没写了 生啊~~~ //深搜 #include #include int array[10]; int a, b, c, d, e, f; int
UDPProbe UDP端口存活探测(发送特征包+响应分析)、UDP服务识别
qDebug() << "收到响应:" << ip.toString() << ":" << port << " 服务:" << serviceName << " 响应长度:" << response.size();qDebug() << "开始探测:" << targetIp << ":" << port << " 超时时间:" << timeout << "ms";qInfo() << "\n==================== UDP探测结果 ====================";
【中国大学生计算机设计大赛信息可视化赛道】国奖项目深入剖析—中国古代奇异怪兽移动端可视化应用项目
【中国大学生计算机设计大赛信息可视化赛道】国奖项目深入剖析—中国古代奇异怪兽移动端可视化应用项目 注:本文主要目的是对于往年国奖项目案例-可视化项目的深入剖析讲解,对源码、项目特点、要点、特色继续深入分析。帮助大家学习技术,掌握规律。
PKU 1018 Communication System
题目:http://poj.org/problem?id=1018 题意:有一个系统有n个设备,每个设备有m个制造商,每个制造商制造的设备的最大带宽和价值是不同的, 题目要求计算n个设备组成的系统中最小的带宽和总价值的最大值,有点绕~~ 思路:选出所有设备的最大带宽和最小带宽,然后从最小带宽枚举到最大带宽,找出每种设备价值最小切带宽大于当前当前带宽~~ #include #in
假人有限元模型
假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用
PKU 1166 The Clocks
题目:http://poj.org/problem?id=1166 题意:给出9个时钟的状态和9种操作,每种操作可以改变不同的时钟的状态,每次只能改变90度,输出最少的有序的操作序列 思路:枚举出每种操作的次数,最多为3次,保存在num数组中,判断每个时钟经过9种,每种num[j]次操作,是否为0. #include #include int flag; int state[9],
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
lwip-2.0.3
lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。
PKU 3624 Charm Bracelet
题目:http://poj.org/problem?id=3624 裸的0-1背包问题 #include #include #include using namespace std; const int maxn=12880; const int maxm=3500; int n, m; int dp[maxn+10], w[maxm+10], d[maxm+10]; in
NTscan扫描工具
ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。
PKU 1151 Atlantis
题目:http://poj.org/problem?id=1151 题意:求矩形并的面积 思路:线段树+离散化+扫描线 #include #include #include #include using namespace std; const int maxn=200; struct SegmentTree { int l, r, cover; double len, sum;
PKU 1177 Picture
题目:http://poj.org/problem?id=1177 题意:墙上贴着一些海报、照片等矩形,所有的边都为垂直或水平。每个矩形可以被其它矩形部分或完全遮盖,所有矩形合并成区域的边界周长称为轮廓周长。 思路:见陈宏论文//一维数组 #include #include #include #include using namespace std; const int max
PKU 3185 The Water Bowls
题目:http://poj.org/problem?id=3185 题意:有20只碗排成一排, 奶牛翻转其中的一只碗, 其左右的碗都会跟着翻转,现在给出20只晚的初始状态,问需要至少多少次的翻转才能使所有碗都朝上。 思路:高斯消元+枚举自由变元。很容易想到如何建立方程组,一共有20个变元和20个方程组,如果有多个自由变元,需要枚举自由变元算出翻转次数,然后取最小值~~~ #include
PKU 1083 Moving Tables
题目:http://poj.org/problem?id=1083 题意:有两排房间,每排200个房间,现在要搬桌子,每搬一次花费10分钟,同一段走廊不能同时使用,求至少花费多长时间。 思路:因为每搬一次桌子就要使用一次s到j的走廊,因此,每次s到j的区间加1,最后求出使用次数最多的*10,即为答案。 需要注意的是,当s为偶数的时候,s--,当t为奇数的时候, t++; #incl
PKU 2761 Feed the dogs
题目:http://poj.org/problem?id=2761 题意:有n个数,给m个区间,求这m个区间的地K大值 思路:裸划分树,与2104相同~~ #include #include #include using namespace std; const int maxn=100000; int n, m, a, b, c; int sorted[m
PKU 1830 开关问题
题目:http://poj.org/problem?id=1830 学完高斯消元做的第一题, 高斯消元的难点在于怎样建立方程组,来建立系数矩阵。如何建方程组:http://blog.youkuaiyun.com/shiren_Bod/article/details/5766907,写的很好, 学习了~~。 此题需要注意的是,初始化矩阵时,开关I和J不要弄反了~~~ 如果有自由变元,返回1
PKU 1651 Multiplication Puzzle
题目:http://poj.org/problem?id=1651 题意:有n个数,取走一个数,计算这个数和他左右两边数的乘积,不允许取最左边和最右边的数,求每次所得的数和的最小值。 思路:不知道怎么DP, 看了discuss, 原来跟矩阵链乘一样,里边分析的很明白了 贴出来~~~, 学习 对于整个牌的序列,最左端和最右端的牌是不能被取走的,除这两张以外的所有牌 ,必然有一张最后取走。取走这
142



被折叠的 条评论
为什么被折叠?



