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 1000010314 at 2014-07-12 15:50:13 on Problem 2253
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

struct Node
{
    long long x,y,step;
};

Node data[210];
int queue[20010];

long long dis(const Node & a, const Node & b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

int main(int argc, const char * argv[])
{
    int n;scanf("%d",&n);
    for(int i=1;n>0;i++,scanf("%d",&n))
    {
        for(int j=0;j<n;j++)
        {
            scanf("%lld%lld",&data[j].x,&data[j].y);
            data[j].step=-1;
        }
        
        queue[0]=0;
        int head,tail;
        for(head=0,tail=1;head<tail;head++)
        {
            for(int j=0;j<n;j++)
            {
                long long tmp=max(data[queue[head]].step,dis(data[j],data[queue[head]]));
                if(data[j].step==-1)
                {
                    data[j].step=tmp;
                    queue[tail++]=j;
                }
                else
                {
                    if(data[j].step>tmp)
                    {
                        data[j].step=tmp;
                        queue[tail++]=j;
                    }
                }
            }
        }
        printf("Scenario #%d\nFrog Distance = %.3f\n\n",i,sqrt((double)data[1].step));
    }
    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