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
1 -5 6
2
2.0000000000
3.0000000000 分类讨论。。如果根是0,单独讨论,不然会输出-0。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath> using namespace std; int main()
{
double a,b,c,det;
scanf("%lf%lf%lf",&a,&b,&c);
det = b * b - * a * c;
if(a == )
{
if(b == && c == )printf("%d",-);
else if(b == )printf("%d",);
else if(c == )printf("%d\n%.10f",,);
else printf("%d\n%.10f",,-1.0 * c / b);
}
else if(b == && c == )
{
printf("%d\n%.10f",,);
}
else if(det < )printf("%d",);
else if(det == )
{
printf("%d\n%.10f",,-0.5 * b / a);
}
else
{
if(a > )printf("%d\n%.10f\n%.10f",,0.5 / a * (- b - sqrt(det)),0.5 / a * (sqrt(det) - b));
else printf("%d\n%.10f\n%.10f",,0.5 / a * (sqrt(det) - b),0.5 / a * (- b - sqrt(det)));
}
}
Equation的更多相关文章
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- coursera机器学习笔记-多元线性回归,normal equation
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...
- CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...
- Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)
,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...
- ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分
Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- SGU 106 The equation
H - The equation Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Subm ...
随机推荐
- 17南宁区域赛 J - Rearrangement 【规律】
题目链接 https://nanti.jisuanke.com/t/19976 题意 给出 一个n 然后 给出 2*n 个数 可以重新排列成两行 然后 相邻的两个数 加起来 不能被三整除 可以上下相邻 ...
- loadrunder之脚本篇——Run-time Settings之Pacing
As soon as the previous iteration ends 前一个迭代一结束就尽可能快的开始新一轮的迭代 After the previous iteration ends ...
- iOS 系统认知 debug distribution release 和 #ifdef DEBUG
debug:调试模式 有调试信息 线下 release: 无调试信息 经过了编译优化 发布 给用户使用的 线上模式 一般 工程项目 都是自带 上述两种配置结构 还有出现 distribution: ...
- css系列(5)css的运用(一)
从本节开始介绍css配合html可以达到的一些效果. (1)导航栏: <html> <head> <title>示例5.1</title> ...
- RocketMQ 笔记-转
Astrotrain概述 Astrotrain是基于阿里巴巴开源项目RocketMQ进行封装的分布式消息中间件系统,提供集群环境下的消息生产和消费功能. RocketMQ介绍 RocketMQ的物理部 ...
- 024_MapReduce中的基类Mapper和基类Reducer
内容提纲 1) MapReduce中的基类Mapper类,自定义Mapper类的父类. 2) MapReduce中的基类Reducer类,自定义Reducer类的父类. 1.Mapper类 API文档 ...
- vuex 入门
vuex.js 状态(数据)管理 在vue中当我们管理数据的时候比较乱,我们要用到下面的这个库,vuex.js Vuex介绍 每一个Vuex应用的核心就是store(仓库),他是用来存储数据的 &qu ...
- Python Streaming实战2: Join的实现与数据过滤
Hadoop Join 与 Not In的实现 (一)源数据与要实现的查询 1. 要实现的查询 select a.sid ,a.name ,b.course ,b.score from Studen ...
- CSS3中新颖的布局方法
本人已经很久没用 bootstrap 什么的了,而现阶段一点卑微的梦想就是自己做框架,毕竟也才入门不久. 所以在寻找布局的共通性/稳定性及拓展性时,会发觉 CSS3 的这三种方法比栅栏布局要有趣得多. ...
- I.mx6s上移植wm8960驱动(基于linux3.0.101版本)
I.mx6s上移植wm8960驱动 此篇博文只记录移植的步骤,其他不做分析.首先上一张wm8960的硬件连接图: 1 上电操作 配置wm8960的上电脚,文件位置:arch/arm/mach ...