Analyzing Polyline CodeForces, polylinecodeforces

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.