• 【模拟赛·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
    

    .

  • 相关阅读:
    【POJ2893&HDOJ6620】M &#215; N Puzzle(n*m数码判定)
    idea破解方法
    ORACLE:MERGE INTO
    DOS命令大全
    使用oracle 的 PL/Sql 定时执行一个存储过程
    spring RestTemplate用法详解
    Oracle截取字符串和查找字符串
    PLSQL Developer常用设置及快捷键
    IntelliJ IDEA设置自动导入包
    Git使用详细教程
  • 原文地址:https://www.cnblogs.com/Damitu/p/7770506.html
Copyright © 2020-2023  润新知