Equation (分类讨论)

机器学习(四):w·x+b模型(1) 假设输入空间x∈Rnx\in R^n, 对于分类问题,我们使用的假设空间为H={h=sign(wTx+b)|w∈Rn,b∈R}H=\{h=sign(w^Tx+b)| w\in R^n, b\in R\} 对于回归问题,我们使用的假设空间为H={h=wTx+b|w∈Rn,b∈R}H=\{h=w^Tx+b|w\in R^n, b\in R\} 其实际意义也比较简单:对于分类问题,用一个超平面将特征 阅读详情

Equation


You are given an equation:

Ax2 + Bx + C = 0.

Your task is to find the number of distinct roots of the equation and print all of them in ascending order.

Input

The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0.

Output

In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.

Example
Input
1 -5 6
Output
2
2.0000000000
3.0000000000

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
    double a,b,c;
    cin >> a >> b >> c;
    if(a == 0 && b == 0){
        if(c == 0) printf("-1\n");
        else printf("0\n");
    }
    else if(a == 0 && c == 0){
        printf("1\n0\n");
    }
    else if(b == 0 && c == 0){
        printf("1\n0\n");
    }
    else if(a == 0){
        printf("1\n");
        printf("%.10f\n",-c/b);
    }
    else{
        double diat = b*b-4*a*c;
        if(diat < 0) printf("0\n");
        else if(diat == 0){
            printf("1\n");
            printf("%.10f\n",(-b/(2*a)));
        }
        else{
            printf("2\n");
            double x1 = (-b-sqrt(diat))/(2*a);
            double x2 = (-b+sqrt(diat))/(2*a);
            if(x1 > x2) swap(x1,x2);
            printf("%.10f\n%.10f\n",x1,x2);
        }
    }
    return 0;
}


【习题集一】监督学习 《机器学习》课程作业集一题解 阅读详情

相关推荐

Rust机器学习实战:回归与分类的生产级实现

机器学习模型部署面临Python生态的运行时不确定性、内存管理脆弱性和跨平台兼容性挑战。Rust凭借零成本抽象、编译期类型安全和静态链接能力,为回归与分类任务提供高确定性数值计算基础。其核心在于ndarray的内存布局优化与linfa的trait-based算法设计,兼顾SIMD向量化性能与FFI互操作性。在金融风控、边缘推理和实时特征工程等对延迟、资源与可靠性敏感的场景中,Rust可显著降低GC停顿、内存抖动与依赖冲突风险,成为Python实验后走向生产环境的关键技术跃迁路径。

a1311010193的博客 399

LaTex: 基础知识

LaTex: 基础知识

吕爽 1207

Android投屏开发实战:手把手教你用Miracast实现Sink端功能(附完整代码)

本文是一份Android投屏Sink端开发的实战指南,详细讲解了如何利用Miracast协议和Wi-Fi P2P技术,从零构建一个功能完整的屏幕接收器。内容涵盖环境搭建、通过反射启用WFD Sink模式、RTSP协议协商、RTP流接收与解析,以及最终使用IjkPlayer进行音视频解码播放的全过程,并附有核心代码示例。

cherry的博客 878

Latex 插入大括号分类情况

演示代码: \documentclass{article} \setlength\textwidth{245.0pt} \usepackage{CJK} \usepackage{indentfirst} \usepackage{amsmath} \begin{CJK*}{GBK}{song} \begin{document} 方法一: $$ f(x)=\left\{ \be...

caoyongsheng的博客 9247

STM32的GPS数据提取程序设计说明——基于NMEA0183协议

一、硬软件平台 本次程序实现效果为对GPS信号穿送来的数据进行筛选,并将筛选后的信息通过上位机显示出来,所以此次设计所需硬件包括STM32F407、RS232转TTL、CH340USB转串口模块,注意该模块在使用前,对应的系统需要安装驱动,否则串口调试助手无法识别,另外还包括JLink下载器。 本次代码设计软件为KEIL5并结合F4固件包,上位机系统为WIN7,主机系统为WIN10。 二、算法总体思路设计 由于GPS通过RS232将数据传送给板子,因此使用两个串口资源(串口1和串口2),其中一个用来

小景的博客 6181

【机器人】机械臂控制入门技术栈分享

机械臂控制入门技术栈分享1.前言2.机器人控制入门技术栈2.1.空间描述和变化2.2.运动学分析2.3.动力学建模2.4.控制入门学习3.进阶部分3.1.机器人参数辨识3.2.非线性控制3.3.现代机器人描述方法:指数坐标4.总结 1.前言 今天看到优快云上有个分享个人技术栈的活动,虽然我不是一个正规的程序员,也不搞前端、后端这些,但我一直在优快云上通过写博客对我的学习进行总结,于是我突发奇想,不如我也写一下我的个人技术栈,针对机械臂控制入门的,因为我水平也不高,所以本文内容也许不够饱满,也不够准确,但

要恰饭得嘛 5856

Latex原创数学文章源代码(2)

关于一元二次含参不等式的一种分类讨论方法

Wing9_的博客 748

天地图API避坑指南:从零开始实现地址搜索与坐标标记

本文是一份天地图API实战避坑指南,详细讲解了从申请密钥、初始化地图到实现地址搜索与坐标标记的全过程。针对开发中常见的坐标偏移、搜索建议不显示、事件监听失效等核心难题,提供了具体的解决方案和代码示例,帮助开发者高效、稳定地集成天地图服务。

weixin_29326909的博客 263

tex ,latex等分类及其区别

前言 在接触TeX两年之后,依然对于TeX的一些术语之间的关系表示不解。比如LaTeX、pdfLaTeX、XeLaTeX、Te...

qq_35478750的博客 3322

基于R语言的PLS算法实现解读

我们使用"pls"包来执行PLS回归,并提供了相应的源代码。在本文中,我们将详细解读基于R语言的PLS算法的实现过程,并提供相应的源代码。PLS算法的实现可以借助R语言中的"pls"包。该包提供了丰富的函数和工具,用于执行PLS回归、PLS-DA(PLS-Discriminant Analysis)和其他相关任务。除了执行PLS回归,"pls"包还提供了其他功能,例如PLS-DA(用于分类问题)和PLS变量选择等。上述代码将基于输入的X值,使用训练好的PLS模型进行预测,并返回预测结果。

TechWhizKid的博客 1043

华为OD机试双机位C卷-敌情监控 (Py/Java/C/C++/Js/Go)

华为OD机试(机考)双机位C卷 【敌情监控】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试 - 敌情监控。

qq_45776114的博客 938

一文熟悉Latex论文排版

一文熟悉Latex论文排版

qq_51447436的博客 1万+

[QMT和ptrade量化交易小白入门]-120、卖出深度虚值期权的三重过滤策略

本专栏主要是介绍QMT和ptrade的基础用法,常见函数,写策略的方法,也会分享一些量化交易的思路,大概会写200篇左右。QMT的相关资料较少,在使用过程中不断的摸索,遇到了一些问题,记录下来和大家一起沟通,共同进步。

木头大左的博客 281

HDU 6627 equation(模拟,分类讨论)

题意:给你n个ai和bi,给你C,求解方程: 分析:初中数学,分类讨论破除绝对值符号。每两个零点之间的区域都对应一个一元一次方程,把这些零点排序之后可以很容易得到每个区间的方程,每个区间都解一个一元一次方程,然后判断解是否在这个区间内。要特判a=0的情况,注意代码细节(写的很搓 代码: #include<bits/stdc++.h> using namespace std; co...

常胜将军的博客 2万+

深度学习100例-卷积神经网络(CNN)彩色图片分类 | 第2天

文章目录前期工作设置GPU导入数据标准化可视化构建CNN网络编译训练模型预测模型评估 前期工作 设置GPU 如果使用的是CPU可以忽略这步 import tensorflow as tf gpus = tf.config.list_physical_devices("GPU") if gpus: gpu0 = gpus[0] #如果有多个GPU,仅使用第0个GPU tf.config.experimental.set_memory_growth(gpu0, True) #设置GPU显存用量

“365天深度学习训练营”报名进行中~ 7853

深度学习工具包 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 6627 equation (分类讨论)

2019 杭电多校 5 1004 题目链接:HDU 6627 比赛链接:2019 Multi-University Training Contest 5 Problem Description You are given two integers \(N,C\) and two integer sequences \(a\) and \(b\) of length \(N\). The...

G19850917的博客 181

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

线性回归

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34293246的博客 86

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

20 B. Equation

题目: 给定一元二次方程的系数,求解。 题解: 分类讨论系数。 代码: #include<iostream> #include<map> #include<cmath> #include<iomanip> using namespace std; typedef long long ll; int main() { double a, b, c; cin >> a >> b >> c; ...

qq_52110074的博客 133

HDU多校 第五场 6227 (equation)

传送门 题意: 对于∑1n∣aix+bi∣=C\sum_1^n|a_ix+b_i| = C∑1n​∣ai​x+bi​∣=C, 求xxx的所有可行解(分数形式表示)。 思路: 分区间讨论。 我们令∣aix+bi∣=0|a_ix+b_i| = 0∣ai​x+bi​∣=0,那么就可以得到nnn个关于 a,ba,ba,b 的解 xix_ixi​,(对每个绝对值编号1~i) 按照 xix_ixi​ 的大小(...

WayJasy的博客 138

640. Solve the Equation

为什么80%的码农都做不了架构师?>>> ...

weixin_34392906的博客 118

3分钟学会:LaTeX2Word-Equation终极公式转换指南

还在为数学公式格式转换而烦恼吗?无论是撰写学术论文还是技术文档,将网页上的数学公式复制到Word文档总是一件让人头疼的事情。LaTeX2Word-Equation这款Chrome浏览器扩展正是为了解决这个痛点而生,它能够智能识别网页中的数学内容,将LaTeX公式无缝转换为Word原生支持的Office Math Markup Language(OMML)格式,彻底打破格式壁垒。无论你是学生、研究人

gitblog_00052的博客 311

【Leetcode】640. Solve the Equation

题目地址: https://leetcode.com/problems/solve-the-equation/ 给定一个字符串形式给出的一元一次方程,要求返回其解,如果有唯一解,则返回"x=#"的形式的字符串;若无穷个解则返回"Infinite solutions";若无解则返回"No solution"。 先将方程按照=做split,然后解析左右两边的x的系数和常数项,最后分类讨论即可。解析的方式是用双指针。对于一个表达式,先将其前面加一个正号(如果以负号开头则不用加),然后维持慢指针永远都是指向正负号,

数学、算法爱好者的博客 332

K - Happy Equation

Description Little Sub has just received an equation, which is shown below, as his birthday gift. ax≡xa(mod 2p)ax≡xa(mod 2p) Given the value of aa, please help Little Sub count the number of xx (1≤x≤2...

名字呢? 647

Turing equation

Turing equation 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 The fight goes on, whether to store  numbers starting with their most significant digit or their least  significant digit. Sometime

穆梓先生 432

LaTeX2Word-Equation终极指南:跨平台公式转换的完整解决方案

在学术写作和技术文档创作中,LaTeX公式与Word文档的格式兼容问题一直是困扰研究人员的技术瓶颈。LaTeX2Word-Equation作为一款创新的Chrome扩展,完美解决了这一痛点,让数学公式在不同平台间实现无缝转换。 ## 快速入门:5分钟完成环境配置 ### 📋 系统要求清单 - **浏览器环境**:Google Chrome 80及以上版本 - **办公软件**:Microso

gitblog_00185的博客 834

LeetCode 640. Solve the Equation C++

640. Solve the Equation Solve a given equation and return the value of x in the form of string “x=#value”. The equation contains only ‘+’, ‘-’ operation, the variable x and its coefficient. If there...

WXM 554
上一篇: Bender Problem
下一篇: You're Given a String... (kmp)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值