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. js/jQuery实现类似百度搜索功能

    一.页面代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  2. Java 基础类型转换byte数组, byte数组转换基础类型

    Java 基础类型转换byte数组, byte数组转换基础类型 Java类型转换 java类对象转化为byte数组

  3. 【转】101个MySQL调试和优化技巧

    MySQL是一个功能强大的开源数据库.随着越来越多的数据库驱动的应用程序,人们一直在推动MySQL发展到它的极限.这里是101条调节和优化MySQL安装的技巧.一些技巧是针对特定的安装环境的,但这些思 ...

  4. Eclipse发布Maven项目到远程服务器

    pom.xml中的配置依赖有两种: 一.tomcat-maven.plugin <plugin> <groupId>org.codehaus.mojo</groupId& ...

  5. 绕过网站安全狗拦截,上传Webshell技巧总结(附免杀PHP一句话)

    这篇文章我介绍一下我所知道的绕过网站安全狗上传WebShell的方法. 思路是:修改HTTP请求,构成畸形HTTP请求,然后绕过网站安全狗的检测. 废话不多说,切入正题.... 1.实验环境: Win ...

  6. JDK8新特性面试

    java8:http://ifeve.com/java-8-features-tutorial/ 一.Lambda表达式和函数式接口 Lambda表达式(也叫做闭包) 它允许我们将一个函数当作方法的参 ...

  7. ZOJ 1011 - NTA

    题目大意:有一颗完全二叉树,给节点一个信号会从一个表中选择一对信号分别传递给两个子节点.最后判断所有叶子节点是否满足给定的规则.题目有点长,具体可参见原题. 首先是表格中数据的存储,由于会有多个元素, ...

  8. Java 之 web.xml(Java之负基础实战)

    多个web.xml会同时生效,先加载tomcat下的web.xml,再加载网站目录下的web.xml. 1.tomcat自带的web.xml 在tomcat的conf目录下 2.自定义web.xml ...

  9. PAT1013 数素数

    思路: 打印素数表 然后找出对应区间[m,n]中的素数 #include <iostream> #include <vector> #include <cmath> ...

  10. Web项目或WCF发布IIS后,如何通过VS2010调试

    在做项目的时候,例如WCF服务一般都会将WCF服务承载于控制台应用程序,或者WinForm窗体应用程序,因为这样可以直接在服务代码上打断点,然后就可以调试了.但是项目已经发布了,当然这里我用的本机进行 ...