代码很好写,下面有我自己写的代码,上面的解析实在太详细,比我自己证的好看的多,就借用一下了,
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 1007
using namespace std;
int t,n;
double k[MAX];
int main ( )
{
scanf ( "%d" , &t );
int c = 1;
while ( t-- )
{
scanf ( "%d" , &n );
double sum = 0.0;
for ( int i = 1 ; i <= n ; i++ )
scanf ( "%lf" , &k[i] ) , sum += k[i];
for ( int i = 1 ; i <= n ; i++ )
scanf ( "%lf" , &k[i] );
printf ( "Case #%d: %.6f\n" , c++ , (n+1)/sum );
}
}