The conic sections are the nondegenerate curves generated by the intersections of a plane with one or two nappes of a cone. For a plane perpendicular to the axis of the cone, a circle is produced. For a plane that is not perpendicular to the axis and that intersects only a single nappe, the curve produced is either an ellipse or a parabola. The curve produced by a plane intersecting both nappes is a hyperbola.
conic section | equation |
---|---|
circle | x2+y2=a2 |
ellipse | x2/a2+y2/b2=1 |
parabola | y2=4ax |
hyperbola | x2/a2-y2/b2=1 |
Input
There are multiple test cases. The first line of input is an integer T ≈ 10000 indicating the number of test cases.
Each test case consists of a line containing 6 real numbers a, b, c, d, e, f. The absolute value of any number never exceeds 10000. It's guaranteed that a2+c2>0, b=0, the conic section exists and it is non-degenerate.
Output
For each test case, output the type of conic section ax2+bxy+cy2+dx+ey+f=0. See sample for more details.
Sample Input
5 1 0 1 0 0 -1 1 0 2 0 0 -1 0 0 1 1 0 0 1 0 -1 0 0 1 2 0 2 4 4 0
Sample Output
circle ellipse parabola hyperbola circle
题意:给出a,b,c,d,e,f,注意是浮点数,根据output给的公式,推出是哪一种图形
思路:因为图形保证存在。d,e只是x跟y的偏移量不需要考虑,且f一定会满足到使其图形存在。根据每个图形公式的性质,很明显得出只要考虑a跟c的关系。当a==c的时候是circle,a*c>0即a与c同号是ellipse,a*c<0异号是hyperbola。剩下的这个parabola很容易跳进坑,这里要保证a*c==0,这里很容易误解为a==0,其实换成c==0也一样。
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<iostream>
using namespace std;
int main(){
int t;
scanf("%d",&t);
while(t--){
double a,b,c,d,e,f;
scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);
if(a*c==0) printf("parabola\n");
else if(a==c) printf("circle\n");
else if(a*c>0) printf("ellipse\n");
else if(a*c<0) printf("hyperbola\n");
}
return 0;
}