首页 > ACM题库 > HDU-杭电 > HDU 3993-Horse Racing[解题报告]HOJ
2015
04-14

HDU 3993-Horse Racing[解题报告]HOJ

Horse Racing

问题描述 :

Tian Ji likes horse racing. Once, he and QI Wei Wang agreement, to carry out a game they discuss the good, to their horses into the upper, middle and lower third-class.

Due to individual differences, each horse’s speed is unique. They started this game, the upper to the upper, middle to middle, lower to lower. Qi Wei Wang’s horses are better than Tian Ji’s horses. So Tian Ji always lost. Sun Bing Tian Ji’s friends gave him an idea. He let lower to upper, upper to middle, middle to lower, as you know. Then Tian Ji won.
Now Tian Ji and Qi Wei Wang host the game again, they all have n horse. As Qi Wei Wang is rich he will give some money to Tian Ji. When Qi Wei Wang lost he give 3 RMB to Tian Ji, when it is tie Qi Wei Wang gives Tian Ji 1 RMB, Of course if Tian Ji loses he would not get any money from Qi Wei Wang.
Every round Tian Ji chooses a horse first, and then Qi Wei Wang chooses a horse haven’t been chosen by random. Tian Ji want you to tell him the Expectation of money he can get. Because Tian Ji has a friend named Sun Bing so he will use the best way to choose horses.

输入:

The first line is an integer t (<=10) indicating the case number. For each case there are three lines, the first line is an integer n (<12) indicating the number of the horses. The next two lines each have n numbers, the first line is the speed of the Qi Wei Wang’s horses, and the second is Tian Ji’s

输出:

The first line is an integer t (<=10) indicating the case number. For each case there are three lines, the first line is an integer n (<12) indicating the number of the horses. The next two lines each have n numbers, the first line is the speed of the Qi Wei Wang’s horses, and the second is Tian Ji’s

样例输入:

2
2
1 2
3 4
2
1 4
2 3

样例输出:

6.000000
3.000000

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>

using namespace std;
int a[20];
int b[20];
int main(){
 int test,n;
 scanf("%d",&test);
 while (test--){
 scanf("%d",&n);
 for (int i=0;i<n;i++)
 scanf("%d",&a[i]);
 for (int j=0;j<n;j++)
 scanf("%d",&b[j]);
 int ans=0;
 for (int i=0;i<n;i++)
 for (int j=0;j<n;j++)
 if (b[i]>a[j]) ans+=3;
 printf("%.6lf\n",ans*1.0/n);
 }
 return 0;
}

  1. #include <stdio.h>
    int main()
    {
    int n,p,t[100]={1};
    for(int i=1;i<100;i++)
    t =i;
    while(scanf("%d",&n)&&n!=0){
    if(n==1)
    printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
    else {
    if(n%4) p=n/4+1;
    else p=n/4;
    int q=4*p;
    printf("Printing order for %d pages:n",n);
    for(int i=0;i<p;i++){
    printf("Sheet %d, front: ",i+1);
    if(q>n) {printf("Blank, %dn",t[2*i+1]);}
    else {printf("%d, %dn",q,t[2*i+1]);}
    q–;//打印表前
    printf("Sheet %d, back : ",i+1);
    if(q>n) {printf("%d, Blankn",t[2*i+2]);}
    else {printf("%d, %dn",t[2*i+2],q);}
    q–;//打印表后
    }
    }
    }
    return 0;
    }