CodeForces 195D(腦洞)
問題描述:
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:
Valeric and Valerko really want to watch the next Euro Championship game, so they asked you to help them.
InputThe 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
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.
1 1 0Output
1Input
3 1 0 0 2 -1 1Output
2Input
3 -2 -4 1 7 -5 1Output
3題目題意:問我們s(x)函式上有多少個不是180°的傾角。
題目分析:我們假象y(x)不是那樣定義的,它就是簡單的一次函式,那麼n個一次函式相加肯定是一次函式,都是180°的傾角(直的),那麼問題就出現在y(x)<0時,y(x)=0,也就是它本身應該加上一個小於0的數結果加上0了,所以就會有彎曲。
也就是記錄與x軸有多少不同的交點
程式碼如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#define ll long long
using namespace std;
set<long double> M;
int main()
{
M.clear();
int n;
scanf("%d",&n);
for (int i=1;i<=n;i++) {
ll k,b;
scanf("%lld%lld",&k,&b);
if (k==0) continue;
else {
long double ans=-(long double)b/k;
if (M.count(ans)==0) M.insert(ans);
}
}
printf("%d\n",M.size());
return 0;
}