HDU 1178 Heritage from father 数学公式 JAVA

Hdu1178Heritage from father Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 5118    Accepted Submission(s): 1811 Problem Description Famous Harry Potter,who se 阅读详情
题意:求 ∑ni=1i∗(i+1)2 ,并用科学计数法保留3位小数表示出来。
思路:写出公式即可: ∑ni=1i(i+1)2=12∑ni=1(i2+i)=12[n(2n+1)(n+1)6+i(i+1)2]
我菜成狗的 java ,吐槽一下,java的BigInteger写起来好爽呀,都是泪。

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

/*********************************************
    Problem : HDU 1178
    Author  : NMfloat
    InkTime (c) NM . All Rights Reserved .
********************************************/

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String argv[]) {
        Scanner cin = new Scanner(System.in);
        BigInteger two = BigInteger.valueOf(2);
        BigInteger six = BigInteger.valueOf(6);
        BigInteger n , ans;
        while(cin.hasNext()) {
            n = cin.nextBigInteger();
            if(n.compareTo(BigInteger.ZERO)==0) break;
            ans = n.multiply(n.multiply(two).add(BigInteger.ONE)).multiply(n.add(BigInteger.ONE)).divide(six);
            ans = ans.add(n.multiply(n.add(BigInteger.ONE)).divide(two)).divide(two);
            String a = ans.toString();
            char A[] = a.toCharArray();
            int lena = a.length();
            if(lena == 1) {
                System.out.printf("%s.00E%d",a,lena-1);
            }
            else if(lena == 2) {
                String b = a.substring(0,1);
                String c = a.substring(1,2);
                System.out.printf("%s.%s0E%d",b,c,lena-1);
            }
            else if(lena == 3) {
                System.out.printf("%c.%c%cE%d",A[0],A[1],A[2],lena-1);
            }
            else {
                if(A[3] >= '5') A[2] ++ ;
                if(A[2] > '9') { A[1] ++ ; A[2] = '0';}
                if(A[1] > '9') { A[0] ++ ; A[1] = '0';}
                if(A[0] > '9') {
                    lena ++;
                    A[0] = '1'; A[1] = '0'; A[2] = '0';
                }
                System.out.printf("%c.%c%cE%d",A[0],A[1],A[2],lena-1);
            }
            System.out.println("");
        }
    }
}
『杭电1178』 Heritage from father Problem Description Famous Harry Potter,who seemd to be a normal and poor boy,is actually a wizard.Everything changed when he had his birthday of ten years old.A huge man called 'Hagrid' found Harry and lead him to a new world full of magic power. If you 阅读详情

相关推荐

手把手教你用SysMax桥接软件搞定CANoe、INCA和刷写工具(附驱动配置避坑点)

本文详细介绍了如何使用SysMax PCAN FD桥接软件实现CANoe、INCA和刷写工具的无缝对接,提供从驱动配置到多软件协同的全链路指南。重点解析了驱动安装避坑点、CANoe配置技巧、INCA集成方法以及刷写工具链优化方案,帮助汽车电子工程师构建高效开发环境。

weixin_30500105的博客 399

hdu---1178Heritage from father

Heritage from father Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submission(s): 4686    Accepted Submission(s): 1665 Problem Description Famous Harry

搬家啦x 651

JavaSpringBoot + VUE 相关开发环境配置合集

1.Java环境-JDK安装 参照:Java基础1-环境篇:JDK安装与环境变量配置 Java基础1-环境篇:JDK安装与环境变量配置_第一段代码的博客-CSDN博客_jdk 2.Web服务器-Tomcat安装 原创Java服务器Tomcat安装和配置 3.Maven(后面为了项目兼容性,使用了3.0.5版本) 原创Maven安装和配置(Maven3.0.5) 4.nginx 原创nginx轻量级Web服务器安装和配置 5 数据库mysql 原创数据库Mysql安装和配置 ...

第一段代码的博客 3172

hdu1178(科学记数法)

#include int main() { double sum; int k,n; while(scanf("%d",&n)==1&&n) { k=0; sum=(n+1)*1.0*n/6.0*(n+2);//必须用n/6.0才能过 while(sum>=10) {

青山绿水之辈 专栏 1202

红米12C刷机避坑指南:NV数据损坏的修复与系统版本选择

本文提供了红米12C刷机过程中避免NV数据损坏的详细指南,涵盖系统版本选择、SP刷机工具使用和fastboot命令修复。重点分析了NV数据损坏的原因与表现,并给出通过工程固件和深度修复技巧解决基带未知、IMEI丢失等问题的实操方案,帮助用户安全完成刷机。

cuda7parallel的博客 1094

CCD 技术介绍(基于innovus引擎CCOpt)

CCD:全称是,并行优化clock和data path。CCOpt:全称是Clock的timing分为两种模式,和。preCTS并没有clock,因此需要建立一个,从clock端口到寄存器CK端的来自sdc中的设置;postCTSupdateIO latency,clock就会自动的转换成propagatedclock,这时就是实际时钟互连线网络的delay。在实际设计中,clock起始于ideal。

m0_61003348的博客 8994

hdu(1178)Heritage from father

水题,主要考察了一个数学公式; #include int main() {     int m,k;     double n;     while(scanf("%d",&m),m)     {         n=1.0*m*(m+1)*(m+2)/6.0;         k=0;         while(n>=10)         {            

飞雪---晨 768

全球气候模式降尺度方法总结及其代码实现

简介总结各类型气候模式降尺度方法

WW、forever的博客 1万+

hdu 1178 Heritage from father

这道题是基本的输出格式问题,还是那句话细节决定成败。 代码 1 #include<stdio.h> 2 #include<math.h> 3 4 int main() 5 { 6 __int64 s,t; 7 double p,q; 8 while(scanf("%I64d",&s)!=EOF&&s) 9 ...

weixin_30363981的博客 112

深度学习特征融合(feature fusion)操作详解

特征融合是指在深度神经网络中,将来自不同来源(如不同网络分支、不同模态、不同时间步、不同空间尺度或不同抽象层级)的特征表示进行有策略地整合,以生成更具判别性、鲁棒性和语义丰富性的联合特征表示。其核心目标是最大化信息互补性,最小化信息冗余与噪声干扰。关键问题:如何“有效”融合?——这取决于任务需求、数据特性、计算资源和融合机制的设计。✅ 是否对齐了空间/通道/模态?✅ 融合方式是否与任务匹配?(检测需定位+语义 → 多尺度融合)✅ 是否引入可学习机制提升适应性?✅ 是否控制了计算开销?

浩瀚之水的专栏 798

简单又好用!分享8个校审编辑常用的ChatGPT提示词指令,高效校对优化你的论文

文稿校对是咱们学术写作中非常重要的收尾步骤,如果单靠人工找出段落中的错别字、语法错误或风格不一致等等问题那真是又费人又费时间了,今天给大家分享几个简单又很有效的专业校对提示词指令,能帮助大家轻松搞定论文的校对工作,效果很明显,让文本清晰、连贯和无错误,并优化完善你的写作风格。通过运行专业明确的提示词指令,可以完成以下几点校对工作:1、ChatGPT可以帮助识别语法、拼写和清晰度问题。2、你可以要求 ChatGPT 简化复杂的句子并改进句子结构。

智能AI让学术科研更容易 1082

hdu 1178

此題有纪念意义:如果两个int数很大,结果需要放到double型里面, 那么第一步请先乘以 1.0,转化成double型否则可能中间结果溢出,导致得不到正确答案 比如 int n; // n可能很大, double sum=0; sum=n*(n+1)*(n+2)/6.0; 如果我们不在第一步乘以1.0,那么n*(n+1) 可能就已经溢出,结果自然是错误的,所以正确的写法是。sum=1.0*n*

the_conquer_zzy的专栏 341

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

HDU1178 Heritage from father【水题】

Heritage from fatherTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submission(s): 6899    Accepted Submission(s): 2584Problem DescriptionFamous Harry Potter,...

海岛Blog 1107

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

深度学习工具包 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 1178 Heritage from father

Heritage from father Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 3783    Accepted Submission(s): 1335 Problem Description Famo

胖子加油! 915

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

HDU 1178Heritage from father

Heritage from father Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131070/65535K (Java/Other) Total Submission(s) : 73   Accepted Submission(s) : 26 Font: Times New Roman | Verdana | Geor

659

Heritage from father

Problem   Link:http://acm.hdu.edu.cn/showproblem.php?pid=1178 原题:

林下的码路 1188

hdu1178

求1,3,6,10,15,21,28……(n*())

穿袜子的流氓兔的专栏 770

hdu1178数学题 Heritage from father

Heritage from father Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 5859Accepted Submission(s): 2107 Problem Description Famo...

weixin_30372371的博客 159

hdu 1178

http://acm.hdu.edu.cn/showproblem.php?pid=1178 等差求和公式s=n(n+1)/2=n/2+n^2/2。。。 sum=1+3+6+………………+i(i+1)(i+2)/6 =1+(1+2)+(1+2+3)+…………(1+2+3+……n) =1/2+1^2/2+2/2+2^2/2+…………n/2+n^2/2 =n(n+1)/2/2+n(n+1)(...

weixin_30575309的博客 124

hdu1178(简单公式)

题目链接:Heritage from father 计算 #include #include #include #include #include using namespace std; int main() { //freopen("in.txt","r",stdin); double n; while(scanf("%lf",

pmt123456的博客 407

hdu 1178 免费馅饼

题意:0~10的位置每秒掉馅饼,为最开始位置为5,每秒最多移动1,最后最多能接到多少馅饼。 设dp【i】【j】表示第i秒位置j接到的最多馅饼数量。 #include #include #include #include #include #include #include #include #include #include ///cout << fixed << setp

uuuuuu 348
上一篇: HDU 1177 "Accepted today?" 水题
下一篇: HDU 1164 Eddy's research I 数论
_NMfloat_
博客等级 码龄12年 7粉丝 315原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址