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 zcmartin at 2015-12-16 17:02:28 on Problem 1328
In Reply To:给大家个数据,希望有用 Posted by:mickeychen at 2010-04-14 19:53:06
#include <iostream>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
struct sa
{
    double x,y,left,right;
}data[1005];
double cmp(const sa&a,const sa&b)
{
    return a.left>b.left;
}
int main()
{
    sa tmp;
    int n;
    double d;
    int k=1;
    while(cin>>n>>d)
    {
        memset(data,0,sizeof(data));
        int sum=1;
        double maxn=0.0,minn=0.0;
        if(n==0||d==0)
            break;
        for(int i=0;i<n;i++)
           {
              cin>>data[i].x>>data[i].y;
              data[i].left=data[i].x-sqrt(d*d-data[i].y*data[i].y);
               data[i].right=data[i].x+sqrt(d*d-data[i].y*data[i].y);
               maxn=max(maxn,data[i].y);
               minn=min(minn,data[i].y);
              // cout<<maxn<<endl;
           }
         //  cout<<maxn<<endl;
        sort(data,data+n,cmp);
        tmp=data[0];
        if(maxn>d||d<=0||minn<0)
        {

            printf("Case ");
            printf("%d",k);
            printf(": ");
             cout<<-1<<endl;
            k++;
            //break;
            continue;
        }
        else
            {
                for(int i=0;i<n;i++)
                    if(sqrt((tmp.left-data[i].x)*(tmp.left-data[i].x)+data[i].y*data[i].y)>d)
                    {
                        sum++;
                        tmp=data[i];
                    }
            }
            printf("Case ");
            printf("%d",k);
            printf(": ");
            cout<<sum<<endl;
            k++;
           // for(int i=0;i<n;i++)
             //   cout<<data[i].left<<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