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

SCU的E,我这样的程序都能AC......

Posted by TN at 2005-09-27 17:28:58
In Reply To:彻底无语...... Posted by:TN at 2005-09-27 17:27:58
当时为什么没有想着胡搞呢......

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <time.h>
#include <math.h>
using namespace std;
const int maxn=10001;
struct point{
    double a,b,c,d;
}a[maxn];
int i,j,k,m,n;
double best;
inline double sqr(double s)
{
    return s*s;
}    
inline double dis(point a1,point a2)
{
    return sqrt(sqr(a1.a-a2.a)+sqr(a1.b-a2.b)+sqr(a1.c-a2.c)+sqr(a1.d-a2.d));
}        
inline bool cmp(point a1,point a2)
{
    return a1.a<a2.a;
}    
inline double min(double a1,double a2)
{
    return a1<a2?a1:a2;
}    
int Random(int st,int ed)
{
    return st+rand()%(ed-st+1);
}    
int main()
{
    while(1)
    {
        scanf("%d",&n);
        if (n==0) return 0;
        for (i=1;i<=n;i++)
            scanf("%lf%lf%lf%lf",&a[i].a,&a[i].b,&a[i].c,&a[i].d);
        best=1000000000;
        sort(a+1,a+n+1,cmp);
        for (i=1;i<=n;i++)
        {
            int ed=min(i+n/150,n);
            for (j=i+1;j<=ed;j++)
            {
                best=min(best,dis(a[i],a[j]));
            }
            if (ed<n)
            for (k=1;k<=(n-j)/150+10;k++)
            {
                int s=Random(ed+1,n);
                best=min(best,dis(a[i],a[s]));
            }    
        }
        if (best>10000) printf("INFINITY\n");
        else printf("%.3lf\n",best);    
    }    
}    

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