Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 111 Accepted Submission(s): 31
What is the range of y?
Each case contains five integers in a single line which are values of A, B, C, D and E (-100 ≤ A, B, C, D, E ≤ 100).
The expression is made up by one interval or union of several disjoint intervals.
Each interval is one of the following four forms: "(a, b)", "(a, b]", "[a, b)", "[a, b]"(there is a single space between ',' and 'b'), where a, b are real numbers rounded to 4 decimal places, or "-INF" or "INF" if the value is negative infinity or positive infinity.
If the expression is made up by several disjoint intervals, put the letter 'U' between adjacent intervals. There should be a single space between 'U' and nearby intervals.
In order to make the expression unique, the expression should contain as minimum of intervals as possible and intervals should be listed in increasing order.
See sample output for more detail.
2012长春的D题,当年只有两个队过,够坑的。
其实就是讨论的情况比较多,折腾了一天终于分析清楚了,还debug了好久。
我是把分母乘过来分析的。
另外一种分析方法见:
http://blog.happybin.org/archives/zoj_3658_simple-function_2012_changchun_site/
我的做法:
代码:
1 /* *********************************************** 2 Author :kuangbin 3 Created Time :2013-10-5 12:05:22 4 File Name :E:\2013ACM\专题强化训练\区域赛\2012长春\D.cpp 5 ************************************************ */ 6 7 #include <stdio.h> 8 #include <string.h> 9 #include <iostream> 10 #include <algorithm> 11 #include <vector> 12 #include <queue> 13 #include <set> 14 #include <map> 15 #include <string> 16 #include <math.h> 17 #include <stdlib.h> 18 #include <time.h> 19 using namespace std; 20 const double eps = 1e-8; 21 int main() 22 { 23 //freopen("d.in","r",stdin); 24 //freopen("out.txt","w",stdout); 25 int A,B,C,D,E; 26 int T; 27 scanf("%d",&T); 28 while(T--) 29 { 30 scanf("%d%d%d%d%d",&A,&B,&C,&D,&E); 31 if(B == D*A && C == E*A) 32 { 33 printf("[%.4lf, %.4lf]\n",1.0*A,1.0*A); 34 continue; 35 } 36 bool fA;//值域包不包含A 37 if(B == D*A)fA = false; 38 else 39 { 40 /* 41 double ttx = (double)(E*A-C)/(B-D*A); 42 if(fabs(ttx*ttx + D*ttx + E) < eps)fA = false; 43 else fA = true; 44 */ 45 int t1 = E*A - C; 46 int t2 = B-D*A; 47 if((long long)t1*t1 +(long long)D*t2*t1 +(long long)E*t2*t2 == 0)fA = false; 48 else fA = true; 49 } 50 if(D*D < 4*E) 51 { 52 int a = D*D - 4*E; 53 int b = 4*A*E + 4*C - 2*B*D; 54 int c = B*B - 4*A*C; 55 double l = (-b+sqrt(1.0*b*b-4.0*a*c))/(2.0*a); 56 double r = (-b-sqrt(1.0*b*b-4.0*a*c))/(2.0*a); 57 if(B != D*A) 58 { 59 if(fA)printf("[%.4lf, %.4lf]\n",l,r); 60 else printf("[%.4lf, %.4lf) U (%.4lf, %.4lf]\n",l,1.0*A,1.0*A,r); 61 } 62 else 63 { 64 if(fabs(A-l) < eps)printf("(%.4lf, %.4lf]\n",l,r); 65 else printf("[%.4lf, %.4lf)\n",l,r); 66 } 67 continue; 68 } 69 if(D*D == 4*E) 70 { 71 int f1 = 4*A*E + 4*C - 2*B*D; 72 double tt1 = (-D)/(2.0); 73 if(f1 == 0)// 74 { 75 if(B*B > 4*A*C) 76 { 77 if(fA)printf("(-INF, INF)\n"); 78 else printf("(-INF, %.4lf) U (%.4lf, INF)\n",1.0*A,1.0*A); 79 } 80 else while(1);//**** 81 //while(1); 82 } 83 else if(f1 > 0) 84 { 85 double l = (double)(-B*B + 4*A*C)/f1; 86 double tt2 = -(B-D*l)/(2*A - 2*l); 87 if(fabs(tt2 - tt1) < eps) 88 { 89 if(!fA) 90 { 91 if(B != D*A) 92 printf("(%.4lf, %.4lf) U (%.4lf, INF)\n",l,1.0*A,1.0*A); 93 else printf("(%.4lf, INF)\n",l); 94 } 95 else printf("(%.4lf, INF)\n",l); 96 } 97 else 98 { 99 if(!fA) 100 { 101 if(B == D*A)printf("(%.4lf, INF)\n",l); 102 else printf("[%.4lf, %.4lf) U (%.4lf, INF)\n",l,1.0*A,1.0*A); 103 } 104 else printf("[%.4lf, INF)\n",l); 105 } 106 } 107 else 108 { 109 double r = (double)(-B*B + 4*A*C)/f1; 110 double tt2 = -(B-D*r)/(2*A - 2*r); 111 if(fabs(tt2 - tt1) < eps) 112 { 113 if(!fA) 114 { 115 if(B != D*A) 116 printf("(-INF, %.4lf) U (%.4lf, %.4lf)\n",1.0*A,1.0*A,r); 117 else printf("(-INF, %.4lf)\n",r); 118 } 119 else printf("(-INF, %.4lf)\n",r); 120 } 121 else 122 { 123 if(!fA) 124 { 125 if(B == D*A)printf("(-INF, %.4lf)\n",r); 126 else printf("(-INF, %.4lf) U (%.4lf, %.4lf]\n",1.0*A,1.0*A,r); 127 } 128 else printf("(-INF, %.4lf]\n",r); 129 } 130 } 131 continue; 132 } 133 if(D*D > 4*E) 134 { 135 double root1 = (double)(-D + sqrt(D*D - 4*E) )/2; 136 double root2 = (double)(-D - sqrt(D*D - 4*E))/2; 137 int a = D*D - 4*E; 138 int b = 4*A*E + 4*C - 2*B*D; 139 int c = B*B - 4*A*C; 140 long long deta = (long long)b*b - (long long)4*a*c; 141 if(deta < 0) 142 { 143 if(fA)printf("(-INF, INF)\n"); 144 else printf("(-INF, %.4lf) U (%.4lf, INF)\n",1.0*A,1.0*A); 145 } 146 else if(deta == 0) 147 { 148 double y0 = (double)(-b)/(2*a); 149 double tt2 = (double)(D*y0 - B)/(2*(A-y0)); 150 if(fabs(tt2 - root1) < eps || fabs(tt2 - root2) < eps) 151 { 152 if(!fA && A < y0 - eps) 153 printf("(-INF, %.4lf) U (%.4lf, %.4lf) U (%.4lf, INF)\n",(double)A,(double)A,y0,y0); 154 else if(!fA && A > y0+eps) 155 printf("(-INF, %.4lf) U (%.4lf, %.4lf) U (%.4lf, INF)\n",y0,y0,(double)A,(double)A); 156 else printf("(-INF, %.4lf) U (%.4lf, INF)\n",y0,y0); 157 } 158 else 159 { 160 if(!fA) 161 printf("(-INF, %.4lf) U (%.4lf, INF)\n",(double)A,(double)A); 162 else printf("(-INF, INF)\n"); 163 } 164 } 165 else 166 { 167 double y1 = (double)(-b-sqrt(1.0*b*b-4.0*a*c))/(2*a); 168 double y2 = (double)(-b+sqrt(1.0*b*b-4.0*a*c))/(2*a); 169 double tt1 = (double)(D*y1 - B)/(2*(A-y1)); 170 double tt2 = (double)(D*y2 - B)/(2*(A-y2)); 171 bool fy1 = true; 172 bool fy2 = true; 173 if(fabs(tt1 - root1) < eps || fabs(tt1 - root2) < eps) 174 fy1 = false; 175 if(fabs(tt2 - root1) < eps || fabs(tt2 - root2) < eps) 176 fy2 = false; 177 if(!fA && fabs(y1 - A) < eps)fy1 = false; 178 if(!fA && fabs(y2 - A) < eps)fy2 = false; 179 if(fy1 && fy2) 180 { 181 if(!fA && A < y1 - eps) 182 printf("(-INF, %.4lf) U (%.4lf, %.4lf] U [%.4lf, INF)\n",(double)A,(double)A,y1,y2); 183 else if(!fA && A > y2 + eps) 184 printf("(-INF, %.4lf] U [%.4lf, %.4lf) U (%.4lf, INF)\n",y1,y2,(double)A,(double)A); 185 else printf("(-INF, %.4lf] U [%.4lf, INF)\n",y1,y2); 186 } 187 else if(fy1 && !fy2) 188 { 189 if(!fA && A < y1 - eps) 190 printf("(-INF, %.4lf) U (%.4lf, %.4lf] U (%.4lf, INF)\n",(double)A,(double)A,y1,y2); 191 else if(!fA && A > y2 + eps) 192 printf("(-INF, %.4lf] U (%.4lf, %.4lf) U (%.4lf, INF)\n",y1,y2,(double)A,(double)A); 193 else printf("(-INF, %.4lf] U (%.4lf, INF)\n",y1,y2); 194 } 195 else if(!fy1 && fy2) 196 { 197 if(!fA && A < y1 - eps) 198 printf("(-INF, %.4lf) U (%.4lf, %.4lf) U [%.4lf, INF)\n",(double)A,(double)A,y1,y2); 199 else if(!fA && A > y2 + eps) 200 printf("(-INF, %.4lf) U [%.4lf, %.4lf) U (%.4lf, INF)\n",y1,y2,(double)A,(double)A); 201 else printf("(-INF, %.4lf) U [%.4lf, INF)\n",y1,y2); 202 } 203 else 204 { 205 if(!fA && A < y1 - eps) 206 printf("(-INF, %.4lf) U (%.4lf, %.4lf) U (%.4lf, INF)\n",(double)A,(double)A,y1,y2); 207 else if(!fA && A > y2 + eps) 208 printf("(-INF, %.4lf) U (%.4lf, %.4lf) U (%.4lf, INF)\n",y1,y2,(double)A,(double)A); 209 else printf("(-INF, %.4lf) U (%.4lf, INF)\n",y1,y2); 210 } 211 } 212 } 213 } 214 return 0; 215 }