USACO section 2.4 Fractions to Decimals(小数处理)

[USACO2.4]分数化小数 Fractions to Decimals 模拟 阅读详情
Fractions to Decimals

Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representation has a repeating sequence of digits, indicate the sequence by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as 0.(3), and 41/333 = 0.123123123...is denoted as 0.(123). Use xxx.0 to denote an integer. Typical conversions are:

1/3     =  0.(3)
22/5    =  4.4
1/7     =  0.(142857)
2/2     =  1.0
3/8     =  0.375
45/56   =  0.803(571428)

PROGRAM NAME: fracdec

INPUT FORMAT

A single line with two space separated integers, N and D, 1 <= N,D <= 100000.

SAMPLE INPUT (file fracdec.in)

45 56

OUTPUT FORMAT

The decimal expansion, as detailed above. If the expansion exceeds 76 characters in length, print it on multiple lines with 76 characters per line.

SAMPLE OUTPUT (file fracdec.out)

0.803(571428)


 

思路:求n/m的小数形式,可以用n/m取得整数部分,小数部分可以有n%=m;n*10;一直重复这步骤直到n为0,或者得到已经出现过的n则说明出现循环节。

          用MAP记录n出现实所在字符串的位置,然后插入括号。输出即可。

失误点:有点急躁,当出正解时忘记了循环小数是输出kans非循环小数是输出ans,结果都输出kans 给WA了一次

           整除小数点后补0忘了WA一次

具体看代码:

 

/*
 ID:nealgav1
 LANG:C++
 PROG:fracdec
*/
#include<fstream>
#include<algorithm>
#include<map>
using namespace std;
ifstream cin("fracdec.in");
ofstream cout("fracdec.out");
const int mm=123456;
char ans[mm],kans[mm];
int main()
{
  int m,n;
  cin>>m>>n;
  map<int,int>mp;
  int len=0;int flag=0;
  while(m)
  {
    flag++;
    if(m/n>=10)
    { int num=m/n;
      while(num)
      { ans[len++]=num%10+'0';num/=10;
      }
      char s;
      for(int i=0,j=len-1;i<j;i++,j--)
      {s=ans[i];ans[i]=ans[j];ans[j]=s;}
    }
    else
    ans[len++]=m/n+'0';
    if(flag==1)ans[len++]='.';
    m%=n;if(mp[m]!=0)break;
    mp[m]=len-1;
    m*=10;
  }
  if(m)
  { copy(ans,ans+mp[m]+1,kans);
    kans[mp[m]+1]='(';
    copy(ans+mp[m]+1,ans+len,kans+mp[m]+2);
    kans[++len]=')';kans[++len]='\0';
    int i;
    for(i=0;kans[i]!='\0';i++)
    if((i+1)%76)
    cout<<kans[i];
    else cout<<kans[i]<<'\n';
    if(i%76!=0)
    cout<<'\n';
  }else
   {if(flag==1)
    ans[len++]='0',ans[len++]='\0';
    int i;
    for(i=0;ans[i]!='\0';i++)
    if((i+1)%76)
    cout<<ans[i];
    else cout<<ans[i]<<'\n';
    if(i%76!=0)
    cout<<'\n';
   }
}


 

Fractions to Decimals
Russ Cox

Remember long division? We know that the decimal expansion is repeating when, after the decimal point, we see a remainder we've seen before. The repeating part will be all the digits we've calculated since the last time we saw that remainder.

We read in the input and print the integer part. Then we do long division on the fractional part until we see a remainder more than once or the remainder becomes zero. If we see a remainder more than once, we're repeating, in which case we print the non-repeated and repeated part appropriately. If the remainder becomes zero, we finished, in which case we print the decimal expansion. When no digits of the decimal expansion have been generated, the correct answer seems to be to print a zero.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#define MAXDIGIT 100100

char dec[MAXDIGIT];
int lastrem[MAXDIGIT];
char buf[MAXDIGIT];

void
main(void)
{
    FILE *fin, *fout;
    int n, d, k, i, rem, len;

    fin = fopen("fracdec.in", "r");
    fout = fopen("fracdec.out", "w");
    assert(fin != NULL && fout != NULL);

    fscanf(fin, "%d %d", &n, &d);
    sprintf(buf, "%d.", n/d);

	/* long division keeping track of if we've seem a remainder before */
    for(i=0; i<MAXDIGIT; i++)
	lastrem[i] = -1;

    rem = n % d;
    for(i=0;; i++) {
	if(rem == 0) {
	    if(i == 0)
		sprintf(buf+strlen(buf), "0");
	    else
		sprintf(buf+strlen(buf), "%s", dec);
	    break;
	}
	if(lastrem[rem] != -1) {
	    k = lastrem[rem];
	    sprintf(buf+strlen(buf), "%.*s(%s)", k, dec, dec+k);
	    break;
	}

	lastrem[rem] = i;
	n = rem * 10;
	dec[i] = n/d + '0';
	rem = n%d;
    }

    /* print buf 76 chars per line */
    len = strlen(buf);
    for(i=0; i<len; i+=76) {
    	fprintf(fout, "%.76s\n", buf+i);
    }
    exit(0);
}

Here's a another, more elegant solution from Anatoly Preygel.

Compute the number of digits before the repeat starts, and then you don't even have to store the digits or remainders, making the program use much less memory and go faster. We know that powers of 2 and 5 are the only numbers which do not result in a repeat, so to find the number of digits before the repeat, we just find the maximum of the differences between the powers of 2 and 5 in the denominator and numerator (see code snippet). Then we just use the first remainder, and output each digit as we calculate it:

#include <iostream.h>
#include <fstream.h>
#include <math.h>
ofstream out("fracdec.out");

int colcount=0;

int numBeforeRepeat(int n, int d) {
    int c2=0, c5=0;
    if (n == 0) return 1;
    while (d%2==0) { d/=2; c2++; }
    while (d%5==0) { d/=5; c5++; }
    while (n%2==0) { n/=2; c2--; } /* can go negative */
    while (n%5==0) { n/=5; c5--; } /* can go negative */
    if (c2>c5)
        if (c2>0) return c2;
        else return 0;
    else
        if (c5>0) return c5;
        else return 0;
}

void print (char c) {
    if (colcount==76) {
        out<<endl;
        colcount=0;
    }
    out<<c;
    colcount++;
}

void print (int n) {
    if (n>=10) print (n/10);
    print ((char)('0'+(n%10)));
}

int main() {
    int n, d;
    ifstream in("fracdec.in");
    in>>n>>d;
    in.close();

    print (n/d);
    print ('.');
    n=n%d;
    int m=numBeforeRepeat(n,d);
    for(int i=0;i<m;i++) {
        n*=10;
	print (n/d);
        n%=d;
    }
    int r=n;
    if(r!=0) {
	print ('(');
        do {
            n*=10;
	    print (n/d);
            n%=d;
        } while (n!=r);
	print (')');
    }
    out<<endl;
    out.close();
    exit (0);
}

 

 

 

 

 

 

USER: Neal Gavin Gavin [nealgav1]
TASK: fracdec
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3600 KB]
   Test 2: TEST OK [0.000 secs, 3600 KB]
   Test 3: TEST OK [0.000 secs, 3600 KB]
   Test 4: TEST OK [0.000 secs, 3600 KB]
   Test 5: TEST OK [0.000 secs, 3600 KB]
   Test 6: TEST OK [0.000 secs, 3600 KB]
   Test 7: TEST OK [0.022 secs, 3864 KB]
   Test 8: TEST OK [0.086 secs, 5052 KB]
   Test 9: TEST OK [0.000 secs, 3600 KB]

All tests OK.

Your program ('fracdec') produced all correct answers! This is your submission #3 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
22 5
------- test 2 ----
1 7
------- test 3 ----
100000 59
------- test 4 ----
1 100000
------- test 5 ----
3 3
------- test 6 ----
59 330
------- test 7 ----
100000 9817
------- test 8 ----
1 99991
------- test 9 ----
982 4885

 

Proxmox VE 从零部署指南:架构解析、安装配置与虚拟机管理 服务器虚拟化技术通过将物理服务器资源抽象、分割和组合,为多个独立的虚拟环境提供计算、存储和网络服务,其核心原理基于Hypervisor(如KVM)或容器化技术。这项技术能显著提升硬件利用率、简化运维并实现快速部署,广泛应用于私有云、开发测试环境及企业IT基础设施。在众多开源虚拟化平台中,Proxmox VE(PVE)集成了KVM虚拟化和LXC容器,提供了强大的Web管理界面和丰富的企业级功能。本文聚焦于PVE的实战部署,详细解析其架构,并指导完成从系统安装、网络与存储配置到创建并优化第一台虚拟机的完整流程, 阅读详情

相关推荐

Fractions to Decimals

Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representation has a repeating sequence of digits, indicate the sequence by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as 0.(3), and 41/333 = 0.123123123...is denoted as 0.(123). Use xxx.0 to denote an integer. Typical conversions are: 1/3 = 0.(3) 22/5 = 4.4 1/7 = 0.(142857) 2/2 = 1.0 3/8 = 0.375 45/56 = 0.803(571428)

USACO2.4.5 Fractions to Decimals 分数化小数(模拟)

Description 写一个程序,输入一个形如N/D的分数(N是分子,D是分母),输出它的小数形式。 如果小数有循环节的话,把循环节放在一对圆括号中。例如, 1/3 = .33333333 写成0.(3) 41/333 = 0.123123123… 写成0.(123) 用xxx.0 成表示整数 典型的转化例子: 1/3 = 0.(3) 22/5 = 4.4 1/7 = 0.(142857) 2/...

bestsort 758

从分立到集成:深入解析Buck电路的核心模块与设计权衡

本文深入解析Buck电路的核心模块与设计权衡,从分立到集成方案的优缺点对比。详细探讨Buck电路的高效能量转换、小型化设计及灵活电压调节能力,并结合实际案例分享分立方案中的PWM生成、反馈环路设计及保护电路优化经验,为工程师提供实用设计参考。

weixin_29306317的博客 222

USACO-Fractions to Decimals

来源:http://ace.delos.com/usacoprob2?a=ecro6SKAJN4&S=fracdec 这题主要是处理循环节的问题。 先考虑竖式除法: 1.设被除数为A,除数为B,试除一次有:B/A=C……D 2.令B不变,被除数变成D*10,再进行试除 3.明显竖式除法是递推定义的,而出现循环节则表示被除数重复出现了,由此算法已经很明显了,不再多说。 ...

anyuan5299的博客 219

从叶片之舞到数据之眼:净空雷达如何重塑风电安全与效率的边界

净空雷达通过激光或毫米波技术实现风机叶片与塔筒间距离的毫米级实时监测,极大提升了风电场在极端天气下的安全性与运营效率。这项技术不仅预防扫塔事故,还通过数据可视化与智能分析赋能叶片健康管理和发电优化,成为风电数字化运维的核心基础设施。

xk7n92h3p5m的博客 1160

超详细流式细胞术全流程解析:从样本制备到结果分析全攻略

流式细胞术(Flow Cytometry)是现代生物学和医学研究中不可或缺的高通量分析技术,可实现对细胞表型、功能状态、细胞周期等多维度参数的快速检测。本文将从实验全流程出发,详解样本制备、上机操作、参数设置及结果处理的核心要点,帮助科研人员精准掌握流式实验关键技术。

good_rrrrr的博客 3868

USACO Section 2.3 Fractions to Decimals

题意: 已知分子分母  求  该数字的小数形式  要求如果是循环小数用()表示出循环节 思路: 不循环小数容易处理  循环小数需要找出哪里是循环节  想象笔算除法的方法可以知道 当被除数的状态再次出现  则表示进入循环  用此方法即可 记录状态时候数组开的大点(我还用了map来映射该状态对应的位置) 因为循环节不一定什么时候出现…  我不会算… 注意: USACO对

House 813

(学习笔记)机器人自主导航从零开始第四步———Rviz、Gazebo、Meshlab的安装

一、Rviz的安装 Rviz是一个

qq_59475883的博客 5057

USACO Section 2.4 Fractions to Decimals

首先答案不可能是无限不循环小数,因为无限不循环小数不能用分数表示。 之所以出现循环是因为余数出现了重复,只需要用数组记录余数出现的位置,用判重来结束循环即可。 #include #include #include #include #include #include #include #include #include using namespace std; /* ID:

一个码农 362

神经网络(十五)在VS Code下搭建PyTorch环境

pytorch在vscode中的配置和使用

就随便写写.... 5万+

Minitab正交试验设计:从入门到精通的完整指南

本文提供了一份使用Minitab进行正交试验设计的完整指南。从正交试验省时省力的原理讲起,详细介绍了在Minitab中创建正交表、填入数据、执行分析(包括解读ANOVA和P值)以及寻找最优参数组合的全流程。文章旨在帮助读者,特别是工艺优化和研发人员,快速掌握这一高效工具,从而用最少的实验次数锁定关键影响因素,提升工作效率与成果。

weixin_29201313的博客 463

USACO-Section 2.4 Fractions to Decimals(模拟)

当某个余数第二次出现时,则循环节为该余数第一次出现至第二次出现之前

idealism_xxm的专栏 459

微生物组数据分析实战:从OTU/ASV过滤到相对丰度转换的标准化流程

本文详细介绍了微生物组数据分析中从原始OTU/ASV表格到标准化相对丰度表格的完整预处理流程。通过基于绝对丰度和出现频率的过滤步骤有效剔除测序噪音与污染,再通过相对丰度转换解决样本间测序深度差异问题,为后续的多样性分析和差异比较奠定可靠基础。文章提供了清晰的R语言实战代码与参数设置思路。

tree的博客 1259

USACO Section 2.4 Fractions to Decimals - 思维不要局限..问题想简单点..

开始这题我是想到的是以前奥数学的那种把循环小数化分数的...那么分母就应该是(99...00)的形式..既然如此..那么找到能被分母整除的最小(99...00)...然后再算出对应的分子..再展开成循环小数...真的很eggache阿...写了一大段..结果都没调出来..     再一想..其实这题只要手动模拟做除法..每次记下除数和余数..再找到有相同余数的就可以了~~而且题目所给的范围

zzyzzy12 1552

026:vue+threeJS 设置地面铺砖的效果

BoxGeometry 是 Three.js 中用于创建立方体或长方体的几何体类。它允许你指定立方体的宽度、高度、深度以及这三个方向上的分段数,从而控制立方体的细分程度。width: 立方体的宽度(沿 x 轴方向)。height: 立方体的高度(沿 y 轴方向)。depth: 立方体的深度(沿 z 轴方向)。widthSegments: 可选参数,指定立方体在 x 轴方向上的分段数,默认值为 1。heightSegments: 可选参数,指定立方体在 y 轴方向上的分段数,默认值为 1。

大剑师兰特的GIS世界 645

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

USACO Section 2.4 Fractions to Decimals(模拟除法)

Fractions to Decimals Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal represen...

angtongyou1893的博客 171

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

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

USACO section2.4 Fractions to Decimals题解&代码

这道模拟倒是出乎意料地顺利… 只是大错不犯小错不断…比如忘记76位换行啊…比如前导零忘记算进位数里啊… 恩总之交了3次才A掉… 关于loop的小技巧就是将原分数化简后分母的因子中5的个数与2的个数的较大值为小数部分的非循环位数,这样只要在计算循环部分时遇到余数相同的情况就可以直接结束了/* ID:rainbow16 LANG:C++ TASK:fracdec */ #include<iostr

Rainbow6174's home 734

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

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

usaco Chapter 2 section 2.4 Fractions to Decimals

 /*ID: niepeng1LANG: C++TASK:fracdec*/#include #include #include #include //#include #define Max1 1001000char s[Max1]={" "};int c[Max1]={0};bool cond[Max1]={false};int main(){ int a,b,tem,tem1,j,i

china1000的专栏 490

USACO Training Section 2.4 Fractions to Decimals

英文原题  中文题译    大意:将有理数表示为小数循环数,如: 1/3     =  0.(3)22/5    =  4.41/7     =  0.(142857)2/2     =  1.03/8     =  0.37545/56   =  0.803(571428) 本身很简单,注意小数循环不是靠字符串的比较,而是除到某位时的商和余数比较,如果商和余数相同,则开始重复。不过在做的...

山中竹笋 141

USACO-Section2.4 Fractions to Decimals【模拟法】

题目描述: 写一个程序,输入一个形如N/D的分数(N是分子,D是分母),输出它的小数形式。 如果小数有循环节的话,把循环节放在一对圆括号中。 例如, 1/3 =0.33333333 写成0.(3), 41/333 = 0.123123123… 写成0.(123), 用xxx.0 等表示整数。 典型的转化例子: 1/3 = 0.(3) 22/5 = 4.4 1/7 = 0.(142857)

tjj1998的博客 214

USACO Section 2.4 Fractions to Decimals (fracdec)

Fractions to Decimals Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal repres...

weixin_30394333的博客 114

usaco-Section 2.4-Fractions to Decimals

Fractions to Decimals Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representatio...

weixin_30768175的博客 92

【USACO 2.4】Fractions to Decimals(分数转小数)

题意:给你N/D的分数,让你输出等价的小数,如果是循环小数,用括号把循环节包起来。如果是整数,后面保留一位小数。每行最多输出76个字符。 题解:模拟除法,如果余数是第二次出现,则代表第一次出现的位置到此为循环节,注意输出,注意输出格式,注意输出每行最多76个字符。学习了一下题解的写法,先写入字符串ans,最后76个一行输出的就很好写了。 /* TASK: fracdec LA...

dingguayi7025的博客 295
上一篇: USACO section 2.4 Bessie Come Home(最短路)
下一篇: USACO section 3.1 Agri-Net(最小生成树,prim)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值