CodeForces 195D(脑洞)

不念不忘少年蓝@ 2022-06-02 05:10 290阅读 0赞

问题描述:

As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that.

Let’s consider a set of functions of the following form:

9aa7cc8d021c2b714c30903f33af9cbd_v_1514842827 Let’s define a sum of n functions y1(x), …, yn(x) of the given type as function s(x) = y1(x) + … + yn(x) for any x. It’s easy to show that in this case the graph s(x)is a polyline. You are given n functions of the given type, your task is to find the number of angles that do not equal 180 degrees, in the graph s(x), that is the sum of the given functions.

Valeric and Valerko really want to watch the next Euro Championship game, so they asked you to help them.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of functions. Each of the following n lines contains two space-separated integer numbers ki, bi ( - 109 ≤ ki, bi ≤ 109) that determine the i-th function.

Output

Print a single number — the number of angles that do not equal 180 degrees in the graph of the polyline that equals the sum of the given functions.

Input

  1. 1
  2. 1 0

Output

  1. 1

Input

  1. 3
  2. 1 0
  3. 0 2
  4. -1 1

Output

  1. 2

Input

  1. 3
  2. -2 -4
  3. 1 7
  4. -5 1

Output

  1. 3

题目题意:问我们s(x)函数上有多少个不是180°的倾角。

题目分析:我们假象y(x)不是那样定义的,它就是简单的一次函数,那么n个一次函数相加肯定是一次函数,都是180°的倾角(直的),那么问题就出现在y(x)<0时,y(x)=0,也就是它本身应该加上一个小于0的数结果加上0了,所以就会有弯曲。

也就是记录与x轴有多少不同的交点

代码如下:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<set>
  6. #define ll long long
  7. using namespace std;
  8. set<long double> M;
  9. int main()
  10. {
  11. M.clear();
  12. int n;
  13. scanf("%d",&n);
  14. for (int i=1;i<=n;i++) {
  15. ll k,b;
  16. scanf("%lld%lld",&k,&b);
  17. if (k==0) continue;
  18. else {
  19. long double ans=-(long double)b/k;
  20. if (M.count(ans)==0) M.insert(ans);
  21. }
  22. }
  23. printf("%d\n",M.size());
  24. return 0;
  25. }

发表评论

表情:
评论列表 (有 0 条评论,290人围观)

还没有评论,来说两句吧...

相关阅读

    相关 wustoj()

    问题描述: 生活在另一个平行宇宙中的HLD,是一个杰出的数学家,他在20岁时就发现了超奇异质数。          作为数学家的他当然是很热爱数字的啦!这天他心血来潮想见识