HDU 4870 rating)

Source: Internet
Author: User
Tags float number
Rating

Time Limit: 10000/5000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 872 accepted submission (s): 545
Special Judge


Problem descriptiona little girl loves Programming Competition very much. recently, she has found a new kind of Programming Competition named "toptoptopcoder ". every user who has registered in "toptoptopcoder" system will have a rating, and the initial value of rating equals to zero. after the user participates in the contest held by "toptoptopcoder", her/his rating will be updated depending on her /His rank. supposing that her/his current rating is X, if her/his rank is between on 1-200 after contest, her/his rating will be min (x + 50 ). her/his rating will be max (X-100, 0) otherwise. to reach 1000 points as soon as possible, this little girl registered two accounts. she uses the account with less rating in each contest. the possibility of her rank between on 1-200 is P for every contest . Can you tell her how her account ratings reach 1000 points?

 

Inputthere are several test cases. Each test case is a single line containing a float number P (0.3 <= P <= 1.0). The meaning of P is described above.

 

Outputyou shoshould output a float number for each test case, indicating the expected Count of contest she needs to participate in. This problem is special judged. The relative error less than 1e-5 will be accepted.

 

Sample input1.0000000.814700

 

Sample output39.00000082.181160

 

Authorfzu

 

Source2014 multi-university training contest 1

A person registers two accounts, and the initial rating is 0. Each time he takes the low score to play the game, he wins and adds 50 points. If he loses, he deducts 100 points. The winning rate is P, he will hit the game until he scored 1000 points on the first day and asked about the expectations of the game.

Solution: There are 231 statuses: (0, 0), (0, 50)... (), (50, 50 ).Gaussian deyuan for expectation.

 

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6  7 double p,A[235][235]; 8 int cnt; 9 struct node10 {11     int i,j;12     node(int i=0,int j=0):i(i),j(j){}13 }map[235];14 const double eps=1e-8;15 int dcmp(double x)16 {17     if(fabs(x)<eps) return 0;18     if(x-0>eps) return 1;19     return -1;20 }21 void swap(int &a,int &b){int t=a;a=b;b=t;}22 inline int max(int a,int b){return a>b?a:b;}23 inline int min(int a,int b){return a<b?a:b;}24 void init()25 {26     cnt=0;27     for(int i=0;i<=20;i++)28     for(int j=i;j<=20;j++)29         map[cnt++]=node(i,j);30 }31 int find(int x,int y)32 {33     int c=0;34     for(int i=0;i<=20;i++)35     for(int j=i;j<=20;j++)36     {37         if(i==x&&j==y)38             return c;39         c++;40     }41 }42 void build_matrix()43 {44     memset(A,0,sizeof(A));45     for(int i=0;i<cnt;i++)46     {47         A[i][i]=1;48         if(map[i].j==20){A[i][cnt]=0;continue;}49         int x=min(map[i].i+1,20),y=map[i].j;50         if(x>y) swap(x,y);51         int pos=find(x,y);52         A[i][pos]-=p;53         x=max(map[i].i-2,0);y=map[i].j;54         pos=find(x,y);55         A[i][pos]-=1-p;56         A[i][cnt]+=1;57     }58 }59 void gauss(int n)60 {61     int i,j,k,r;62     for(i=0;i<n;i++)63     {64         r=i;65         for(j=i+1;j<n;j++)66             if(fabs(A[j][i])>fabs(A[r][i])) r=j;67         if(dcmp(A[r][i])==0) continue;68         if(r!=i) for(j=0;j<=n;j++) swap(A[r][j],A[i][j]);69         for(k=0;k<n;k++) if(k!=i)70             for(j=n;j>=i;j--) A[k][j]-=A[k][i]/A[i][i]*A[i][j];71     }72     for(i=n-1;i>=0;i--)73     {74          for(j=i+1;j<cnt;j++)75             A[i][cnt]-=A[j][cnt]*A[i][j];76          A[i][cnt]/=A[i][i];77     }78 }79 int main()80 {81     init();82     while(~scanf("%lf",&p))83     {84         build_matrix();85         gauss(cnt);86         printf("%.6lf\n",A[0][cnt]);87     }88     return 0;89 }

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.