Harmonic Number LightOJ - 1234

ethercat linux lan9252 - lan9253调试 linux 的ethercat测试 阅读详情

题目:Harmonic Number   LightOJ - 1234

题意: 求   Hn

思路:题意十分的简单,但是看到这道题第一想法就是暴力,后来发现有T次查询,如果暴力指定超时,所以就想到了打表,打表的时间复杂度是O(n),查询时O(1),但是问题来了数据范围最大到1e8,内存会爆掉的,所以就需要优化一下节约内存,所以可以采用分段打表,100数打一个表,空间是1e6那么内存就不会。

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn  = 1e6+5;
const int INF = 1e8+5;
double a[maxn];
void init(){//打表
    double tmp = 0;
    for(int i = 1; i <= INF; i++){
        tmp += double(1.0/i);
        if(i % 100  == 0){
            a[i/100] = tmp;
        }
    }
}
int main(){
    int T;
    init();
    cin>>T;
    int ca = 0;
    while(T--){
        int n;
        scanf("%d", &n);
        int t = n / 100;//算出n在那一块
        double ans = a[t];
        for(int i = t * 100+1; i <= n; i++){//剩下的部分
            ans += 1.0/(i*1.0);
        }
        printf("Case %d: %.10lf\n",++ca, ans);
    }
return 0;
}

还有一种方法就是利用公式的方法, 参考博客:Harmonic Number(调和级数+欧拉常数)

公式:f(n)=ln(n)+C+1/(2*n), 公式中C≈0.57721566490153286060651209;但是使用的时候n不能过小, 10000以上的数就可以用这个公式,剩下的就是打表,10000以内的数打表应该非常容易。

代码:

#include<bits/stdc++.h>
using namespace std;
const double  C = 0.57721566490153286060651209;
const int maxn = 100000;
double a[maxn];
void Init(){
     a[1] = 1;
     for(int i = 2; i <= maxn; i++){
        a[i] = a[i-1]+double(1.0/i);
     }
}
int main(){
    int T;
    Init();
    cin>>T;
    int ca = 0;
    while(T--){
        int n;
        scanf("%d", &n);
        if(n <= maxn)printf("Case %d: %.10lf\n",++ca, a[n]);
        else {
            printf("Case %d: %.10lf\n",++ca, log(n)+C+double(1.0/(2*n)));
        }
    }

return 0;
}

 

AutoSAR系列讲解(入门篇)2.2-SWC的类型 该章讲解了两种SWC的分类,并且映射到实际的工程中应该是具体的什么文件类型 阅读详情

相关推荐

Source Insight 4.0舒适黑主题 仿心情看的舒服就行

Source Insight 4.0主题 仿心情看的舒服就行 source insight自带的主题怎么看怎么别扭,于是在试用全网各种主题配色后,在其中一个基础上自定义了c/c++的语法配色 截全图有点糊 函数定义 全局变量 局部变量 枚举变量引用 全局变量引用及结构体成员 宏定义引用 ----------------------后面会再把主题文件贴上来-------------- ...

weixin_43443402的博客 1312

I - Harmonic Number LightOJ - 1234

链接点击打开链接In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers:In this problem, you are given n, you have to find Hn.InputInput starts with an integer T (...

D-DeepWave的博客 430

Linux下XDMA驱动调试实战:从PCIe枚举到DMA性能调优

PCIe枚举是设备与主机通信的基础,涉及BAR空间映射和配置空间访问。XDMA作为Xilinx的PCIe DMA IP核,其驱动probe流程和DMA描述符机制直接影响数据传输效率。在FPGA加速卡和数据采集卡等场景中,掌握XDMA调试技巧能显著提升系统稳定性和吞吐量。本文围绕PCIe枚举、BAR映射、DMA描述符、MSI-X中断等关键环节,深入剖析Linux环境下XDMA驱动的常见问题与性能调优方法,帮助工程师快速定位硬件链路、IP配置及驱动层的故障。

weixin_29171129的博客 220

LightOJ Harmonic Number 1234【技巧】

1234 - Harmonic Number PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB In mathematics, the nth harmonic number is the sum of the

豫帝哥哥 1725

ContextCapture、EPS、CASS3D房地一体详细操作流程

还是房地一体的作业流程,这次我们整合了ContextCapture操作流程部分以及EPS和CASS3D三维采集绘制房屋及地形。结合房地一体项目全流程来分享新技术带来的便利。 第一步还是前期资料准备,这里不多赘述,可以参考之前的文章→ 房地一体工作浅谈(一)——资料准备 房地一体工作浅谈(二)——外业工作 关于外业及内业处理部分可参考我们之前的文章:无人机航测从外业作业到内业处理,我们有一整套实战教程!(精灵4RTK外业部分) 下面是我们整合的ContextCapture、EPS、CASS3D三个软件的操作.

qq_43173805的博客 1万+

基于ESP32的智能停车场管理系统开发

智能停车场管理系统通过引入物联网(IoT)技术,实现对停车场内车辆的实时监控、空闲车位的管理、车辆的入场与出场控制等功能,大大提高了停车场的利用率和管理效率。通过集成物联网技术、云平台以及先进的传感器和执行器,系统不仅能实时监控停车场的车位状态,还能提供更好的用户体验。本文将介绍如何基于ESP32开发一个智能停车场管理系统,涵盖系统架构、硬件选择、软件开发以及最新技术的应用,帮助开发者实现高效的智能停车管理。ESP32的代码主要负责处理车位传感器的数据,控制LED指示灯的状态,以及与云平台进行数据交互。

2201_76125393的博客 924

Harmonic Number (LightOJ-1234)

Problem Description In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers: In this problem, you are given n, you have to find Hn. Input Input sta...

Alex_McAvoy的博客 342

RK3588 平台部署实战:OpenCV + LibTorch + FFmpeg 环境搭建与深度学习推理全流程解析

现在,你已经掌握了在RK3588上搭建OpenCV+LibTorch+FFmpeg环境的完整流程,也完成了深度学习模型的部署测试。不妨从一个具体的应用场景入手(如检测自家宠物的品种),亲手打造属于你的第一个边缘智能应用——当你看到模型在RK3588上精准输出结果时,你会发现:嵌入式深度学习的门槛,其实并没有想象中那么高。这些依赖是编译OpenCV、FFmpeg的基础,安装过程中若提示权限不足,可在命令前加。若能输出预测的类别索引,则说明环境搭建成功,模型推理流程通畅。文件,实现模型加载、图像预处理与推理。

FJN110的博客 551

lightoj 1234 Harmonic Number

题目及时给你一个调和级数让你求它的和,不过直接求是不可能的,肯定超时,所以这里就要用到欧拉常数了,当数据比较小的时候直接暴力,当数据超过一定范围的时候,就用这个公式f(n) = ln(n) + c + 1/(2*n);其中才就是欧拉常数。。。。。。。 当然还有其他方法,就是分段打表然后根据数据的大小先从表中选取数据,然后在循环暴力出结果 这里给出第一种方法的代码! In ma

W_904038290的博客 405

SAP 合并报表(EC-CS)完整方法论 + 全业务操作步骤

SAP合并报表(EC-CS)方法论与操作指南摘要 SAP EC-CS模块提供完整的集团合并解决方案,其核心方法论基于会计准则和集团管控逻辑,通过6大维度构建标准化合并体系:组织架构标准化、数据采集标准化、外币换算规则化、内部交易自动化抵消、股权与商誉规范化、报表出具灵活化。 实施过程分为两个阶段: 上线前配置阶段(12个步骤):包括合并架构搭建、科目表配置、外币规则设定、抵消规则定义等基础工作 日常操作阶段(10个步骤):涵盖数据报送、外币换算、内部对账、自动抵消、调整分录等月结流程 系统优势包括: 支持多

金牌架构师 1395

uniapp:在map地图组件上添加控件,在地图上添加浮层展示自定义按钮或元素,uniApp如何在Map组件地图上添加悬浮在上面的图标/图片(全平台兼容安卓苹果app、H5网页、微信小程序、nvue)

uni-app的map添加控件问题,uniapp实现地图展示控件,uniapp小程序如何在map组件上增加按钮,uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,Uniapp腾讯地图添加控件,uniapp百度地图添加控件,地图上展示控件并可以点击,在地图上展示控件信息,uniapp map地图怎么向地图上增加工具栏,使用cover-view将控件在地图上展示,解决uniapp map上添加浮层无法显示问题,不显示怎么办,css样式不生效,地图等最高层

✅ 精选推荐文章 3239

lightoj 1234 - Harmonic Number 【分块打表】

题目链接:lightoj 1234 - Harmonic Number

世界很大 442

拉曼光谱入门:9.光谱仪校准--从Ne灯到标准硅片

本文系统阐述了拉曼光谱仪从氖灯原子发射谱线波长校准、卤素灯强度响应校正到标准硅片520.7 cm⁻¹峰验证的完整计量流程,建立了涵盖波长精度、强度响应与光谱分辨率的多维校准体系及其计量溯源链。

qq_53529450的博客 185

LightOJ1234 Harmonic Number

1 /* 2 LightOJ1234 Harmonic Number 3 http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1234 4 打表 分块 5 由于只有加法运算,1e8时间是可以承受的。 6 然而空间无法承受,于是以50个单位为一块进行分块。 7 ...

dianan9456的博客 213

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

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

LightOJ 1234 Harmonic Number

LightOJ 1234 Harmonic Number In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers: In this problem, you are given n, you have to find Hn. Input Input starts with an integer T (≤ 10000), denoting the number

旺崽的博客 2606

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LightOJ1234 Harmonic Number 调和级数

LightOJ1234 Harmonic Number 标签 调和级数 前言 我的csdn和博客园是同步的,欢迎来访danzh-博客园~ 简明题意 求调和级数 思路 用公式:S(n)=ln(n)+r+12nS(n)=ln(n)+r+\frac 1{2n}S(n)=ln(n)+r+2n1​ 如果对精度要求更高的话,可以分段打表 注意事项、 无 总结 无 AC代...

danzh 231

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

【数学】 LightOJ 1234 Harmonic Number

题目地址:http://lightoj.com/volume_showproblem.php?problem=1234 数据到10^8,刚好可以循一轮,那么我们就用预处理的思想(但是不保存),一次性把答案处理出来然后再去输出。 之前忘记考虑重复了WA了一发。 #include #include #include #include using namespace st

曜雨丶的博客 623

LightOJ1234 Harmonic Number —— 分区打表

题目链接:https://vjudge.net/problem/LightOJ-1234 1234 - Harmonic Number PDF (English) Statistics Forum Time Limit:3 second(s) Memory Limit:32 MB In ...

alince20008的博客 159

lightoj1234Harmonic Number

题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 sb题,分块打表就行#include <stdio.h> #include<iostream> #include<algorithm> #include<cmath> #include<cstring> using namespace std; double ans[100001

IDrandom的专栏 419

LightOJ1234(Harmonic Number)

解法1(分块打表) 将打表结果分块,解决内存不足的问题,是一个很实用的技巧。 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long lo...

qq_42835440的博客 246

LightOJ 1234 - Harmonic Number

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1234 题意:求下面这个Hn。 题解:哈哈哈哈哈,这又是一个高数调和级数啦。前面就打表啊。当数字很大的时候可以用公式。 截图自百度百科,就是很大的时候公式就是 lnk+1/2k+C这个C是欧拉常数。C = 0.57721566490153286...

deze1991的专栏 203

LightOJ 1234 Harmonic Number

题目链接:点我In mathematics, the nth harmonic number is the sum of the reciprocals of the first n natural numbers:In this problem, you are given n, you have to find Hn. InputInput starts with an integer T (≤

wood 477
上一篇: 欧拉回路,欧拉通路的判断方法
下一篇: Leading and Trailing LightOJ - 1282
Re:fused
博客等级 码龄9年 474粉丝 162原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址