【题目链接】: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的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 604D】Moodular Arithmetic

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. [置顶] openHAB 体系结构与编程模型 (1) --- 术语

    openHAB 术语 Item : 对硬件设备属性的抽象 ( Items are objects that can be read from or written to in order to int ...

  2. python_字典的使用

    '''info = { "stu1":"Lie","stu2":"Weite","stu3":&qu ...

  3. SpringBoot中使用过滤器Filter

    场景:API的参数都是经过加密的,于是在过滤器中,将获取到的请求的参数先解密再去进行处理 一.实现Filter接口 public class TestFilter implements Filter ...

  4. MySQL主从复制与读写分离(非原创,谢绝膜拜)

    MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 Mysql作为目前世界上使用最广泛的免费数据库,相信所有从事系统运维的工程师都一定接触过.但在实际的生产环境中, ...

  5. 2015 Multi-University Training Contest 5 hdu 5349 MZL's simple problem

    MZL's simple problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  6. UVA 11404 Palindromic Subsequence

    Palindromic Subsequence Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA ...

  7. WinServer-IIS-woff字体不显示问题

    ASP.NET mvc发布到IIS之后,访问网站的时候,发现woff字体没有加载 百度发现很多博客上的教程是这样的,在IIS管理器中的MIME选项中添加类型 但是重新使用IIS发布后,新添加的字体就会 ...

  8. echarts 设置x轴的和y轴的属性

    axisLabel:{ interval:0,//横轴信息全部显示 rotate:-30,//-30度角倾斜显示 } splitNumber:10

  9. JQuery与CSS之图片上放置button

    position:relative日常应用的时候通常是设置给position:absolute;的父层的, 父层position:relative; 子层position:absolute;的话, 就 ...

  10. jQuery中focusin()和focus()、find()和children()的差别

    jQuery中focus()和focusin().focus()和children()的差别 focus()和focusin() focus()和focusin()的差别在于focusin()支持事件 ...