1541 - Student’s question

时间限制:1秒 内存限制:128兆

696 次提交 134 次通过
题目描述

YYis a student. He is tired of calculating the quadratic equation. He wants you to help him to get the result of the quadratic equation. The quadratic equation’ format is as follows: ax^2+bx+c=0.

输入

The first line contains a single positive integer N, indicating the number of datasets. The next N lines are n datasets. Every line contains three integers indicating integer numbers a,b,c (a≠0).

输出

For every dataset you should output the result in a single line. If there are two same results, you should just output once. If there are two different results, you should output them separated by a space. Be sure the later is larger than the former. Output the result to 2 decimal places. If there is no solution, output “NO”.

样例输入
3
1 2 1
1 2 3
1 -9 6
样例输出
-1.00
NO
0.73 8.27

题目链接:http://acm.hust.edu.cn/problem/show/1541

分析:此题坑点很多!比赛中看到有人WA了11次都没过!原因在于要取double型而非int型,取double,直接AC,虽然弱弱也WA了3次才想到这一点!
大意就是要求解方程的根,常规做法就是先判断△=b*b-4*a*c的值,小于0无解,输出NO;等于0,一解;大于0,两解!但要注意的是两个解要从小到大进行有序输出!
而如何求解x1,x2,根据韦达定理得:x1+x2=-b/a,x1*x2=c/a去求解x1-x2=sqrt((x1+x2)*(x1+x2)-4*x1*x2),然后就可以求出x1,x2啦!还要记得保留两位小数哟!
下面给出AC代码:

 #include <bits/stdc++.h>
using namespace std;
int main()
{
double n,a,b,c;
while(cin>>n)
{
while(n--)
{
cin>>a>>b>>c;
if(a==)break;
else
{
if(b*b-*a*c>=)
{
double t1=(-b)/a;
double t2=c/a;
double t3=sqrt(t1*t1-*t2);
double x1=(t1+t3)/;
double x2=(t1-t3)/;
if(x1==x2) cout<<fixed<<setprecision()<<x1<<endl;
else if(x1<x2)
cout<<fixed<<setprecision()<<x1<<" "<<x2<<endl;
else if(x1>x2)
cout<<fixed<<setprecision()<<x2<<" "<<x1<<endl;
}
else cout<<"NO"<<endl;
}
}
}
return ;
}

HUST 1541 Student’s question的更多相关文章

  1. HUST 1541 解方程

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6394836.html 1541 - Student’s question 时间限制:1秒 内存限制 ...

  2. 识别简单的答题卡(Bubble sheet multiple choice scanner and test grader using OMR, Python and OpenCV——jsxyhelu重新整编)

    该博客转自www.pyimagesearch.com,进行了相关修改补充. Over the past few months I've gotten quite the number of reque ...

  3. Objective-C:在类中设置不同协议

    在下面的代码中,设置了两种不同的协议规则:一种是老师对学生设置的协议:即老师发出命令后,学生站起来.回答问题.坐下; 另一种是我对学生设置的协议:即学生按照我的协议中的初始化函数去初始化一个整数. / ...

  4. CF#335 Lazy Student

    Lazy Student time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Codeforces Round #335 (Div. 2) D. Lazy Student 贪心

    D. Lazy Student   Student Vladislav came to his programming exam completely unprepared as usual. He ...

  6. Codeforces Round #335 (Div. 2) D. Lazy Student 构造

    D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...

  7. t检验,T Test (Student’s T-Test)

    1.什么是T test? t-test:比较数据的均值,告诉你这两者之间是否相同,并给出这种不同的显著性(即是否是因为偶然导致的不同) The t test (also called Student’ ...

  8. Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造

    题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...

  9. Educational Codeforces Round 34 A. Hungry Student Problem【枚举】

    A. Hungry Student Problem time limit per test 1 second memory limit per test 256 megabytes input sta ...

随机推荐

  1. isKindOfClass,isMemberOfClass使用备忘

    isMemberOfClass 判断是否是属于这类的实例isKindOfClass 判断是否是这个类或者这个类的子类的实例 if ([teacher isKindOfClass:[Teacher cl ...

  2. Extjs的架构设计思考,单页面应用 or 多页面?

    写在前面:不要认为 EXTJS 高版本就是一个界面改良,在项目中,仍然用 N 张页面,在 N 张页面部署 EXTJS .这种方式不用多讲,效率问题大家都看得出来, EXTJS 是一个集成开发工具,注定 ...

  3. mysql 之SQL语句--NSERT SELECT ON DUPLICATE KEY UPDATE的写法

    Table source CREATE TABLE `source` ( `key` int(11) NOT NULL AUTO_INCREMENT, `data` int(11) DEFAULT N ...

  4. jquery核心功能分析

    作者:zccst 核心功能包括: jQuery是如何定义的,如何调用的,如何扩展的.掌握核心方法是如何实现的,是理解jQuery源码的关键.这里理解了一切豁然开朗. 1,如何定义,即入口 // Def ...

  5. C++通过Callback向C#传递数据,注意问题

    转载:出处 现在比较流行C#与C++融合:C#做GUI,开发效率高,C++做运算,运行效率高,二者兼得. 但是C++与C#必然存在数据交互,C#与C++dll的数据交互从来都是一个让人头疼的问题. 从 ...

  6. linux下源码编译安装mysql

    1.安装依赖的包: yum install -y gdb cmake ncurses-devel bison bison-devel 2.创建mysql安装目录和数据文件目录 mkdir -p /us ...

  7. Linux内核配置浅析

    1.Linux Kernel Kconfig系统的基本结构 Linux内核的配置系统由三个部分组成,分别是: 1>.Makefile:分布在 Linux 内核源代码根目录及各层目录中,定义 Li ...

  8. java系列--类和对象

    一.成员属性,构造方法,成员方法 1.类名首字母一般大写 2.方法名的首字母一般是小写,使用驼峰法(匈牙利法) myCry, 下划线法 my_cry 3.方法的声明没有函数体(接口,抽象类),数据类型 ...

  9. Ubuntu安装飞鸽传输

    飞鸽传书下载地址 http://www.ipmsg.org.cn/ipmsg/download.html 下载以后解压压缩包,会有一个可执行文件,executable文件. ./Qipmsg 如果没报 ...

  10. Compilation err ororg.eclipse.jdt.internal.compiler.classfmt.ClassFormatException

    严重: Compilation errororg.eclipse.jdt.internal.compiler.classfmt.ClassFormatExceptionat org.eclipse.j ...