Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

竟然把中间值当做int型!!!wrong了好久啊 ,贴下代码吧

Posted by 1A2012 at 2014-08-25 20:00:36 on Problem 1328 and last updated at 2014-08-25 20:01:23
#include"stdio.h"
#include"string.h"
#include"math.h"
#include"iostream"
#include"algorithm"
using namespace std;
#define N 1005
struct node
{
    double l,r;
}p[N];
double x[N],y[N];
bool cmp(node a,node b)
{
    return a.l<b.l;
}
int main()
{
    int i,n,d,cnt=1,flag;
    while(scanf("%d%d",&n,&d),n||d)
    {
        flag=0;
        for(i=0;i<n;i++)
        {
            scanf("%lf%lf",&x[i],&y[i]);
            if(flag)
                continue;
            if(d<y[i])
                flag=1;
            double t=sqrt(d*d-y[i]*y[i]);
            p[i].l=x[i]-t;
            p[i].r=x[i]+t;
        }
        printf("Case %d: ",cnt++);
        if(flag)
        {
            printf("-1\n");
            continue;
        }
        sort(p,p+n,cmp);
        int t=1;
        double rr;  //好郁闷啊
        rr=p[0].r;
        for(i=1;i<n;i++)
        {
            if(p[i].l>rr)
            {
                rr=p[i].r;
                t++;
            }
            if(p[i].r<rr)
            {
                rr=p[i].r;
            }
        }
        printf("%d\n",t);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator