HUST 1541 Student’s question
1541 - Student’s question
时间限制:1秒 内存限制:128兆
- 题目描述
-
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 - 分析:此题坑点很多!比赛中看到有人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的更多相关文章
- HUST 1541 解方程
参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6394836.html 1541 - Student’s question 时间限制:1秒 内存限制 ...
- 识别简单的答题卡(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 ...
- Objective-C:在类中设置不同协议
在下面的代码中,设置了两种不同的协议规则:一种是老师对学生设置的协议:即老师发出命令后,学生站起来.回答问题.坐下; 另一种是我对学生设置的协议:即学生按照我的协议中的初始化函数去初始化一个整数. / ...
- CF#335 Lazy Student
Lazy Student time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心
D. Lazy Student Student Vladislav came to his programming exam completely unprepared as usual. He ...
- 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 ...
- t检验,T Test (Student’s T-Test)
1.什么是T test? t-test:比较数据的均值,告诉你这两者之间是否相同,并给出这种不同的显著性(即是否是因为偶然导致的不同) The t test (also called Student’ ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
- 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 ...
随机推荐
- (简单) POJ 2387 Til the Cows Come Home,Dijkstra。
Description Bessie is out in the field and wants to get back to the barn to get as much sleep as pos ...
- iOS 添加导航按钮
iOS设置导航按钮navigationBar中包含了这几个重要组成部分:leftBarButtonItem, rightBarButtonItem, backBarButtonItem, title. ...
- mysql 大树据表update很慢
问题描述: 数据表千万量级,update where gid="adadfadsfasdf",返回结果显示耗时70ms到1s之间 分析: 表很大,那么update,可能先要取索引 ...
- IOS第三方数据库--FMDB
iOS中原生的SQLite API在使用上相当不友好,在使用时,非常不便.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB.PlausibleDatabase.sqlitepers ...
- 《OpenCV3 计算机视觉--Python语言实现 第二版》源代码及纠错
1.源代码下载地址 <OpenCV3 计算机视觉--Python语言实现 第二版>由我们翻译,英文书名<Learning OpenCV3 Computer Vision with P ...
- Android与JNI(三) ---- c++调用java(转载)
源码下载:JniDemo JNI就是Java Native Interface, 即可以实现Java调用本地库, 也可以实现C/C++调用Java代码, 从而实现了两种语言的互通, 可以让我们更加灵活 ...
- javascript---jquery (1事件)
1.例子说明 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- Zend Framework Module之多模块配置
摘要:该文将为大家简单介绍一下如何使用zend framework创建模块化的应用程序. zend framework对多模块的支持是很好的,但是可能是由于功能太过强大的缘故,部署起来并不是很容易.许 ...
- struts配置文件和国际化
一.加载包struts2-core-2.3.24.1.jar struts-default.xml :各种栈 org.apache.struts2 -->> default.propert ...
- Outlook 2013 电子邮件账户设置备份与恢复
与之前版本不同,Outlook 2013需要备份以下注册表内容:HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Profiles恢复时 ...