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

怎么就错了呢?谁有空帮忙看一看,谢谢!!!

Posted by 10121540117 at 2014-05-20 16:20:19 on Problem 1328
#include <iostream>
#include <stdlib.h>
#include <cmath>

using namespace std;

int main()
{
    struct Data
    {
        double x,y;
    }data[1001];
    int n,t=1;
    double d;
    while(cin>>n>>d,n || d)
    {
        int i,j;
        for(i=0;i<n;i++)
        {
            cin>>data[i].x>>data[i].y;
        }
        for(i=n-1;i>0;i--)
        {
            for(j=0;j<i;j++)
            {
                if(data[j].x>data[j+1].x)
                {
                    Data tem=data[j+1];
                    data[j+1]=data[j];
                    data[j]=tem;
                }
                if(data[j].x==data[j+1].x && data[j].y<data[j+1].y)
                {
                    Data tem=data[j+1];
                    data[j+1]=data[j];
                    data[j]=tem;
                }
            }
        }
        int cnt=1;
        double pos=sqrt(d*d-data[0].y*data[0].y)+data[0].x;
        for(i=1;i<n;i++)
        {
            if(data[i].y>d) {cnt=-1;break;}
            if((data[i].x-pos)*(data[i].x-pos)+data[i].y*data[i].y<=d*d) continue;
            else
            {
                pos=sqrt(d*d-data[i].y*data[i].y)+data[i].x;
                cnt++;
            }
        }
        if(n==0) cnt=0;
        cout<<"Case "<<t++<<": "<<cnt<<endl;
    }
    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