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到吐血,求高人指点!!!!

Posted by sunqian1998 at 2012-06-04 21:01:38 on Problem 3413 and last updated at 2012-06-04 21:04:18
#include<iostream>
using namespace std;
int n,a[11],b[11],s[11],d,c[11]={0},f1=1,f2=1,x[11]={0},m[11]={0,1,2,3,4,5,6,7,8,9,10},maxp=0;
int gcd(int i,int j)
{
    if(i>j) swap(i,j);
    if(i==0) return j;
    else return gcd(j%i,i);
}
void point(int p)
{
     f1=1;
     f2=1;
     for(int i=1;i<=n;i++)
     {
       if(p>=b[c[i]]) p+=s[c[i]];
       else
       {
         if(p<=a[c[i]]) return;
         f1*=p-a[c[i]];
         f2*=b[c[i]]-a[c[i]];
       }
     }
     int k=gcd(f1,f2);
     f1/=k;
     f2/=k;
     f1*=2000;
     int j=f1/f2;
     if(j%2==0) j/=2;
     else j=(j+1)/2;
     if(j>=maxp) 
     {
       maxp=j;
       for(int i=1;i<=n;i++) m[i]=c[i];
     }
}
void pl(int i)
{
     if(i==n+1) 
     {
        point(d);
        return;
     }
     for(int j=1;j<=n;j++)
     {
        if(x[j]==0)
        {
           c[i]=j;
           x[j]=1;
           pl(i+1);
           x[j]=0;
        }
     }
}
void print()
{
     cout<<maxp/1000<<".";
     if(maxp%1000<10) cout<<"00";
     if(maxp%1000>=10 && maxp%1000<100) cout<<"0";
     cout<<maxp%1000<<endl;
     for(int i=1;i<=n;i++)
     {
         cout<<m[i];
         if(i!=n) cout<<" ";
     }
     cout<<endl; 
}
int main()
{
    cin>>n>>d;
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>s[i];
    pl(1);
    print();
    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