【模拟赛·polyline】

Input file: polyline.in

Output file: polyline.out

Time limit: 1s

Memory limit: 128M

有若⼲个类似于下⾯的函数: 定义 n 个函数 y1(x), ..., yn(x) 的对于任意 x 的总和 s(x) = y1(x) + ... + yn(x),很容易发现 s(x) 的图象是多段线组成。给你 n 个函数,你的任务是找出 s(x) 图象不等于 180 度的⾓的个数。

Input

第⼀⾏⼀个整数 n,表⽰函数的个数。接下来 n ⾏, 每⾏包含两个空格隔开的整数 ki , bi , 表⽰第 i 个函数的参数。

Output

输出⼀⾏⼀个整数, 表⽰形成的多段线的图像中不等于 180 度⾓的个数。

Example polyline.in

polyline.out

1 1 0 1 3 1 0 0 2 -1 1 2 3 -2 -4 1 7 -5 1 3

Scoring

对于 30% 的数据,n ≤ 3000。

对于 100% 的数据,1 ≤ n ≤ 105 , −109 ≤ ki , bi ≤ 109。

【题解】

       ①图像画出来就是一条折线,然后求拐点就是了。

       ②特殊情况:k为0直接删掉,将于x轴交点横坐标排序,如果这一个等于前一个,ans--

       ③由于k,b很大,因此精度要求极高,long double。

#include<bits/stdc++.h>
#define go(i,a,b) for(int i=a;i<=b;i++)
int n,ans,t,k,b;long double x[100004];
int main()
{
	scanf("%d",&n);
	go(i,1,n){scanf("%d%d",&k,&b);
	if(k)x[++t]=-(long double)b/(long double)k;}
	
	std::sort(x+1,x+t+1);ans=t;
	go(i,2,t)if(fabs(x[i]-x[i-1])<1e-18)ans--;
	printf("%d
",ans);return 0;
}//Paul_Guderian

.

原文地址:https://www.cnblogs.com/Damitu/p/7770506.html