【codeforces 20B】Equation
【题目链接】:http://codeforces.com/contest/20/problem/B
【题意】
给你一个方程,让你输出这个方程的解的情况.
【题解】
a==0,b==0,c==0时,为恒等式,无穷解;
a==0,b==0,c!=0时,为恒不等式,无解;
a==0,b!=0,为一次方程,有唯一解-c/b
a!=0的时候,按照正常的二次方程求解;
x1和x2的关系可能会因为a的正负改变的,不能直接输出,要判断一下大小再控制输出;
【Number Of WA】
4
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("D:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6+100;
const int MOD = 1e9+7;
LL a,b,c;
double temp;
int main(){
//Open();
Close();
cin >> a >> b >> c;
if (a==0 && b==0 && c==0){
cout <<-1<<endl;
return 0;
}
if (a==0 && b==0 && c!=0){
cout <<0<<endl;
return 0;
}
if (a==0 && b!=0){
cout <<1<<endl;
double ans = (-1.0)*c/b;
cout << fixed << setprecision(10) << ans << endl;
return 0;
}
temp = b*b-4*a*c;
if (temp<0){
cout <<0<<endl;
}else if (temp==0){
cout <<1<<endl;
double ans = -1.0*b/(2*a);
cout << fixed << setprecision(10) << ans << endl;
}else if (temp>0){
cout <<2<<endl;
temp = sqrt(temp);
double ans1 = (-1.0*b-temp)/(1.0*2*a),ans2 = (-1.0*b+temp)/(1.0*2*a);
if (ans1>ans2) swap(ans1,ans2);
cout << fixed << setprecision(10) << ans1 <<endl<<ans2<<endl;
}
return 0;
}
【codeforces 20B】Equation的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 604D】Moodular Arithmetic
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
随机推荐
- hp soap扩展最全说明,附天气预报调用的例子
自从php5开始,我们可以不用通过php nusoap来创建php soap web service 和调用 soap了,php5内置了 soap扩展.只需要在php.ini中开启soap的exten ...
- 安装SSH、配置SSH无密码登录 ssh localhost
集群.单节点模式都需要用到 SSH 登陆(类似于远程登陆,你可以登录某台 Linux 主机,并且在上面运行命令),Ubuntu 默认已安装了 SSH client,此外还需要安装 SSH server ...
- js中的json操作
js中的json操作 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScr ...
- H5知识点
一.总体变化 1.H5文档结构 <!DOCTYPE html> <html> <head> <title> 这是标题 </title> ...
- 解决ORA-28002: 密码7天之后过期办法
https://www.douban.com/group/topic/46177516/ https://yq.aliyun.com/ziliao/42484 http://blog.csdn.net ...
- SQL SERVER-in,between,like
and 1 LIKE 操作符用于在 WHERE 子句中搜索列中的指定模式 ( 可以使用正则表达式) select * from [User] where UserName like '%r' -- 以 ...
- 怎样制作C#安装程序
近期须要制作一个C#安装.在网上找了一些资料发现都不是非常完整,最后自己综合了一些资料,而且通过亲自检測,最后成功完毕C#打包成安装程序(打包成最简单的一种安装程序.假设须要更高的功能请自己在开发). ...
- windows+ubuntu双系统,在windows中访问ubuntu文件
今天被告知ubuntu磁盘空间不足,百度得知可以通过autoremove命令清理,然而,,再也进不去ubuntu系统了,具体表现为第一次选择ubuntu之后一直是空白紫屏,如果强制关机再开机后选择ub ...
- nyoj--528--找球号(三)(位运算&&set)
找球号(三) 时间限制:2000 ms | 内存限制:3000 KB 难度:2 描述 xiaod现在正在某个球场负责网球的管理工作.为了方便管理,他把每个球都编了号,且每个编号的球的总个数都是偶数 ...
- Parquet学习总结
深入分析Parquet列式存储格式 Parquet是面向分析型业务的列式存储格式,由Twitter和Cloudera合作开发,2015年5月从Apache的孵化器里毕业成为Apache顶级项目,最新的 ...