Analyzing Polyline CodeForces, polylinecodeforces
Analyzing Polyline CodeForces-195D
There are n functions. The I function yi (x) = max (ki * x + bi, 0 ). Defines the function s (x) = y1 (x) + y2 (x) +... + yn (x ). Obviously, the image of function s is a line. Find the number of turning points on the line.
Method: If ki is equal to 0 for each image of function yi (x), there is no turning point. Otherwise, there is a turning point, that is, at the point (-bi/ki, 0) (that is, the function value is set to max (0, 0) = 0 ). If function yi and yj have two different turning points, then the function images they correspond to will obviously have two turning points. If function yi and yj have two identical turning points, then they and the functional images will obviously have only one turning point. The number of turning points of function s is the number of different turning points from y1 to yn, that is, the number of different-bi/ki.
1 # include <cstdio> 2 # include <set> 3 using namespace std; 4 set <long double> s; 5 int n, k, B; 6 int main () 7 {8 int I; 9 scanf ("% d", & n); 10 for (I = 1; I <= n; I ++) 11 {12 scanf ("% d", & k, & B); 13 if (k! = 0) s. insert (-(long double) B)/k); 14} 15 printf ("% d", s. size (); 16 return 0; 17}
Http://blog.csdn.net/dlpf_c/article/details/76012830