【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 ...
随机推荐
- Node.js 指南(迁移到安全的Buffer构造函数)
迁移到安全的Buffer构造函数 移植到Buffer.from()/Buffer.alloc() API. 概述 本指南介绍了如何迁移到安全的Buffer构造函数方法,迁移修复了以下弃用警告: 由于安 ...
- 通过CSS样式隐藏百度版权标志
在JSP中添加: //隐藏所有.anchorBL{ display:none; } //隐藏下方的保留百度地图图片 .BMap_cpyCtrl{ display:none; } 注:维护他人版权, ...
- git 简单理解
现在git这个版本控制大行其道,弄了半天大概理解了一下他的工作原理. 使用流程 1,安装git ,小乌龟,小乌龟汉化(在设置里面第一项,检查更新,下载中文包安装) 2,设置 小乌龟 ->git ...
- POJ 1107
水题一道,注意取模时不能为0 #include <iostream> #include <algorithm> #include <cstring> #includ ...
- linux文件与用户和群组
文件基本属性 在图片中alogrithm的文件属性为drwxrwxr-x,其中d代表此文件为目录. 后面rwx,rwx,r-x分别代表文件所属者(ower),组(group),其他用户(other)的 ...
- MongoDB 数据库下载和安装
MongoDB是一款非常流行的非关系型数据库,将面向对象数据存储做的非常好.这里就不具体介绍它的使用,本文主要解说怎样安装MongoDB数据库.把自己安装过程中碰到的问题和最后解决方法分享给大家,希望 ...
- JavaWeb错误处理集锦
一:起因 (1)自己接下来想走算法的路子,打算把十大算法和数学模型学习一下,算是给自己之前 JavaWeb 的一个总结: (2)记得Java算是第一个比較上手的语言了,更是用JavaWeb走过了非常长 ...
- ArcGIS Server 10.2 公布Oracle11g数据源的 Feature Service
安装好arcgis server 10.2及 Desktop 而且确保 arcgis server manager 能够正常启动执行载入服务 1.Oracle 配置 安装好Oracleserver端程 ...
- iOS开发- 生成/解析.vcf文件
vcf, 通讯录导出的一种格式. 一.生成vcf文件 假设要把我们iPhone通讯录里的数据, 生成vcf格式文件. 我们能够借助iCloud. 小技巧:通过iCloud导出iPhone通讯录的方法 ...
- js判断是对象还是集合
/*============================================ 函数功能:对返回数据中的列表数据进行非空处理 ============================== ...