poj 2352-Stars

POJ-2352(Stars)树状数组解法 题目原网址:http://poj.org/problem?id=2352又是一道星星的题,下面是题目描述(本人翻译):题目描述天文学家经常检查星图,其中恒星由平面上的点表示,每颗恒星都有笛卡尔坐标。让恒星的水平是恒星的数量,而恒星并不高于恒星的右边。天文学家想知道恒星的分布。例如,查看上图中显示的地图。星号5的水平等于3(它由三颗星形成,数字为1,2和4)。而且,编号为2和4的恒星的等级为1.在该... 阅读详情

链接:http://poj.org/problem?id=2352

因为题目给出的数据y是非递减的,所以y可以直接忽略掉,题目不是很难,比较适合练手,给出线段树和树状数组做的代码


线段树:

#include<stdio.h>
#include<string.h>
#define MAXN 32010
int sum[15010];
struct node
{
    int l,r;
    int s;
}t[4*MAXN];
void construct(int l,int r,int p)
{
    t[p].l=l;
    t[p].r=r;
    t[p].s=0;
    if(l==r)
        return ;
    int m=(l+r)/2;
    construct(l,m,p*2);
    construct(m+1,r,p*2+1);
}
int query(int l,int r,int p)
{
    if(t[p].l==l&&t[p].r==r)
        return t[p].s;
    int m=(t[p].l+t[p].r)/2;
    if(r<=m)
        return query(l,r,p*2);
    else if(l>m)
        return query(l,r,p*2+1);
    else
        return query(l,m,p*2)+query(m+1,r,p*2+1);
}
void insert(int x,int p)
{
    if(t[p].l==t[p].r&&t[p].l==x)
    {
        t[p].s++;
        return ;
    }
    int m=(t[p].l+t[p].r)/2;
    if(x<=m)
        insert(x,p*2);
    else
        insert(x,p*2+1);
    t[p].s=t[p*2].s+t[p*2+1].s;
}
int main()
{
    int n,i,x,y;
    while(scanf("%d",&n)!=EOF)
    {
        memset(t,0,sizeof(t));
        memset(sum,0,sizeof(sum));
        construct(0,32001,1);
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&x,&y);
            insert(x,1);
            sum[query(0,x,1)-1]++;
        }
        for(i=0;i<n;i++)
            printf("%d\n",sum[i]);
    }
    return 0;
}

树状数组:

#include<stdio.h>
#include<string.h>
#define MAXN 15010
int ans[MAXN],c[MAXN*2+3000];
int lowbit(int x)
{
	return x&(-x);
}
int sum(int i)
{
	int s=0;
	while(i>0)
	{
		s+=c[i];
		i-=lowbit(i);
	}
	return s;
}
void add(int i,int val)
{
	while(i<=32001)//需要一层一层地往上更新数组
	{
		c[i]+=val;
		i+=lowbit(i);
	}
}
int main()
{
	int n,x,y,i;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&x,&y);
			ans[sum(x+1)]++;
			add(x+1,1);
		}
		for(i=0;i<n;i++)
			printf("%d\n",ans[i]);
	}
	return 0;
}


poj 2352 stars(树状数组,线段树) 这是一道很不错的题目,即可以用线段树做也可以用树状数组,可谓经典。不过当然了线段树是比较难搞,而树状数组是极其简洁的,构造很简单,下面就分别来介绍一下两种方法... 立即下载

相关推荐

从零搭建基于OpenSpec的现代化UI自动化测试框架实战指南

UI自动化测试是软件质量保障的关键环节,其核心在于通过脚本模拟用户操作,对Web应用界面进行功能验证。其原理在于利用浏览器驱动工具(如Selenium、Playwright)提供的API,实现对页面元素的定位、交互与断言。一个设计良好的自动化框架能显著提升测试脚本的可维护性、可读性和执行稳定性,从而在持续集成、回归测试等场景中发挥巨大价值。本文聚焦于如何构建一个现代化的UI测试框架,通过整合OpenSpec架构规范、Pytest测试引擎与Playwright浏览器自动化工具,形成清晰的页面对象模型(POM)

weixin_28836989的博客 285

poj2352——二维偏序+树状数组

题目链接:http://poj.org/problem?id=2352 目录 Description Input Output Sample Input Sample Output Description 天文学家经常研究星图,星图上的星星由平面上的点表示,每颗星星都有笛卡尔坐标。一颗星星的等级是指该星星左下方的星星的数量. 例如,查看上图所示的地图,5号星的等级为3...

mumei的博客 972

三电平逆变器LC滤波设计避坑指南:从SVPWM谐波到Simulink仿真验证

本文详细解析了三电平逆变器LC滤波设计中的关键问题,从SVPWM谐波特性到Simulink仿真验证,提供了800V/10kW系统的参数计算方法和优化技巧。通过实际案例和仿真配置示例,帮助工程师避免常见设计误区,提升电能质量和系统稳定性。

weixin_29261711的博客 173

poj 2352 星星的等级

复习一个简单的线段树题目 输入点已经按照y坐标递增的顺序排列,所以按照x区间就行 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #in

cfzjxz的专栏 558

RK3568/RK3588之修改8250驱动实现RS485收发的自动切换

在串口发送前,若为485,则将控制引脚拉为发送状态,在发送后,循环查看是否发送完成,若发送完成则将引脚置回读状态,如此一来,就能实现在内核测控制方向切换,而不会因为延时造成数据丢失,经过测试此办法可行。全部修改完成后,重新编译生成内核文件和设备树文件,烧写到板子上即可。

哒宰的博客 3112

实战避坑:在Ubuntu 22.04上配置NVIDIA GPU Direct RDMA时,必须搞清的P2P DMA与IOMMU那些事

本文深入探讨在Ubuntu 22.04上配置NVIDIA GPU Direct RDMA时P2P DMA与IOMMU的关键问题,解析PCIe架构中的地址转换、P2P DMA与标准DMA的区别,以及IOMMU对性能的影响。通过实战案例和调优建议,帮助用户避免常见配置陷阱,提升AI训练集群的数据传输效率。

weixin_33720078的博客 441

【POJ 2352】树状数组

1.题目链接。题目大意:给定n个点,对每一个点,求一下这个点左下方有多少个点。(左下方的定义就是:横纵坐标同时小于等于这个点的坐标)。 2.分析:由于题目比较良心,输入的时候y就是有序的,所以其实我们只需要统计一下横坐标小于等于这个点的数的数量即可。那么就比较简单了,我们对x轴建一颗树状数组,初始化为0,每次输入一个数据,把这个数据插入到树状数组里面,注意这里的插入其实是逻辑上的插入,也就是不是...

YG爱木木 301

安装keil5(MDK)及导入pack包教程

首先说明的是我安装的Keil版本为Keil V5.29.0.0 1、安装软件 右键管理员权限运行安装包 设置安装路径以及pack的存放路径 随意输入First Name和E-mail 安装驱动 完成软件安装,然后可以先关闭弹出的Pack Install(一会再添加) 2、激活一下软件 打开桌面的Keil File → License Management(我之前注册过了) 右...

hrx-@@ 10万+

POJ - 2352  Stars

POJ - 2352  Stars Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that ...

YIU 330

Cadence——原理图相关教程

包含创建文件,原理图,元器件,规则检查,PDF与BOM清单输出,各类PCB网表

haonanyayaya的博客 1万+

C++经典面试题100例及答案

答:把一些具有共性的对象归类后形成一个集合,也就是所谓的类。答:这样可以提高编译效率,因为分开的话只需要编译一次生成对应的.obj文件后,再次应用该类的地方,这个类就不会被再次编译,从而大大的提高了编译效率。答:这种函数会自动为内联函数,这种函数在函数调用的地方在编译阶段都会进行代码替换。答:常对象是指在任何场合都不能对其成员的值进行修改的对象。答:所谓的回调函数,就是预先在系统的对函数进行注册,让系统知道这个函数的存在,以后,当某个事件发生时,再调用这个函数对事件进行响应。

usstmiracle的博客 3万+

POJ-2352-Stars

POJ-2352-Stars http://poj.org/problem?id=2352 给出n个星星的坐标,如果一个星星的左下方(包含正左和正下)有k颗星星,就说这颗星星是k级的,统计每个等级有多少个点。这题可用树状数组,对于每个星星按y坐标从小到大排序,相同y坐标按x坐标从小到大排序(题目中数据已经有序),输入顺序已排好序,那么只要依次统计星星i之前x坐标小于等于i.x的星星有多少,即是

菜鸟的程序人生 2433

【数据集】2019年中国1km格网河网密度数据集

中国1km格网河网密度数据集

WW、forever的博客 1342

poj 2352 Stars(线段树)

poj 2352 Stars(线段树)

PKU_ZZY的博客 885

深度学习工具包 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")

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ 2352 Stars

POJ 2352 Stars Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of th...

anhaoti3785的博客 117

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

树状数组 poj2352 Stars

2019-05-20 22:52:07 加油,坚持,加油,坚持 !!! #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int MAXN = 32005; int c[MAXN],level[MAXN],n; ...

weixin_30662109的博客 92

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

【树状数组】POJ 2352 Stars

POJ 2352 Stars 题意:在笛卡尔坐标系上给出星星坐标,按照y坐标升序(y坐标相等,x坐标升序)给出。规定星星的等级为其左下方的星星数量,求各等级的星星的个数。 思路:由于星星是按照y坐标升序(y坐标相等,x坐标升序)给出的,所以我们找该星星的左下的星星数量,就是当前输入该星星坐标之后getsum(x)-1,“-1”是因为要减去该星星本身。 注意:为了防止add( 0 ),所以我们每个...

L_X_ 167

POJ2352 Stars

题目大意: 在坐标上有n个星星,如果某个星星坐标为(x, y), 它的左下位置为:(x0,y0),x0 按照y递增,如果y相同则x递增的顺序给出n个星星,求出所有level水平的数量。 一维的树状数组,

alpc_wt的专栏 634

POJ 2352 Stars (线段树)

POJ 2352 Stars (线段树) 手动博客搬家:本文发表于20170819 22:11:49, 原地址https://blog.youkuaiyun.com/suncongbo/article/details/77417650 URL: http://poj.org/problem?id=2352 题目大意:给定n个点(n<=15000), 每个点有坐标(x, y...

suncongbo's blog 112

POJ 2352 Stars(树状数组)

题目链接: POJ 2352 Stars 题意: 每个星星的level是纵坐标小于等于它并且横坐标小于它的星星的数量。按照y从小到大,其次x从小到大的顺序给出n个星星的坐标,输出level从0到n-1的星星的数量。 分析: 由于给出的坐标是优先按照y排序的,那么直接对每个星星查找x的树状数组值然后更新就好了。//556K 375MS #include <cstdio> #include <

ramay7 447
上一篇: hdu 4112 Break the Chocolate
下一篇: hdu 2492 Ping pong
yjCola
博客等级 码龄14年 4粉丝 138原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值