CodeForces - 195D —D. Analyzing Polyline

本文介绍了一种计算由特定形式的线性函数之和构成的折线图中非180度角数量的方法。通过输入不同参数的线性函数,程序能够找出这些函数相加后形成的折线图中有多少个角度不等于180度。

D. Analyzing Polyline
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

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.

Examples
input
1
1 0
output
1
input
3
1 0
0 2
-1 1
output
2
input
3
-2 -4
1 7
-5 1
output
3
只考虑k!=0的情况,每条直线对应一个分界点x,当直线大于或小于x是时y的值才不为0,否则y一直为0,此时k也一直为0,所以只需计算有几个不同的x值即可。要使用long double   要不卡精度

#include<iostream>
#include<stdio.h>
#include<set>
#define maxn 100010
using namespace std;
int main()
{
    int k,b;
    int n,i;
    set<long double> s;
    while(scanf("%d",&n)!=EOF)
    {
        s.clear();
        for(i=0;i<n;i++)
        {
            scanf("%d%d",&k,&b);
            if(k!=0)
                s.insert((long double)b/k);
        }
        printf("%d\n",s.size());
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值