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

麻烦各位看下程序,WA了快20次了...

Posted by Rubbish_Oh at 2009-08-23 18:56:40 on Problem 3744
#include <stdio.h>
#include <math.h>
#include <algorithm>
int n;
double p;
int x[20];
double ans[20];
int main()
{
   while (scanf("%d %lf",&n,&p)!=EOF)
   {
      for (int i=0;i<n;i++) scanf("%d",&x[i]);
      std::sort(x,x+n);
      
      ans[0]=(pow(p-1,x[0]-1)-1.0)/(p-2);
      for (int i=1;i<n;i++)
        ans[i]=ans[i-1]*(1-p)*(pow(p-1,x[i]-x[i-1]-1)-1.0)/(p-2);
      double e=ans[n-1]*(1-p);
      printf("%.7lf\n",fabs(e));
   }
   
   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