UVA 10382

来源:互联网 发布:淘宝自己提兑换码 编辑:程序博客网 时间:2024/05/12 00:21
#include <iostream>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <cmath>#include <algorithm>using namespace std;#define MAXN 10010#define eps 1e-8struct node{    double l,r;}spr[MAXN];int cmp( node a, node b){   return a.l < b.l;}int N;double len, W, cen, rad;int main(){    while(scanf("%d %lf %lf",&N, &len, &W) != EOF)    {        for( int i = 0; i < N; i++)        {            scanf("%lf %lf",&cen, &rad);            double res = sqrt(rad * rad - (W * W/2/2));            spr[i].l = cen - res;            spr[i].r = cen + res;        }        sort(spr, spr + N, cmp);        double L, R;        R = 0;        int ans = 0;//        for( int i = 0; i < N ; i++)//           cout<<spr[i].l<<"->"<<spr[i].r<<endl;//        cout<<"+++++++++++++++++++++++++++++++++++++"<<endl;        while( R + eps < len)        {            L = R;           // cout<<L<<"            "<<R<<endl;            for( int i = 0; i < N; i++)            {                if(spr[i].l <= L && spr[i].r > R)                     R = spr[i].r;                if(spr[i].l > R)                 break;            }            if(L == R)              {                  ans = 0;                  break;              }            ans++;        }        if(ans == 0)         printf("-1\n");        else        printf("%d\n",ans);    }    return 0;}
0 0
原创粉丝点击