牡丹江的水題們

這些是上週末的時候做了一下的牡丹江的題目,由於時間不足,只做了一點,不是參加了區域賽。但是明年希望自己能去區域賽呢!加油↖(^ω^)↗



Average Score


Time Limit: 2 Seconds      Memory Limit: 65536 KB

Bob is a freshman in Marjar University. He is clever and diligent. However, he is not good at math, especially in Mathematical Analysis.

After a mid-term exam, Bob was anxious about his grade. He went to the professor asking about the result of the exam. The professor said:

"Too bad! You made me so disappointed."

"Hummm... I am giving lessons to two classes. If you were in the other class, the average scores of both classes will increase."

Now, you are given the scores of all students in the two classes, except for the Bob's. Please calculate the possible range of Bob's score. All scores shall be integers within [0, 100].

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains two integers N (2 <= N <= 50) and M (1 <= M <= 50) indicating the number of students in Bob's class and the number of students in the other class respectively.

The next line contains N - 1 integers A1A2, .., AN-1 representing the scores of other students in Bob's class.

The last line contains M integers B1B2, .., BM representing the scores of students in the other class.

Output

For each test case, output two integers representing the minimal possible score and the maximal possible score of Bob.

It is guaranteed that the solution always exists.

Sample Input

2
4 3
5 5 5
4 4 3
6 5
5 5 4 5 3
1 3 2 2 1

Sample Output

4 4
2 4

這道題目是簡單的水題,只是在理解題意的時候還有點問題,剛剛開始沒讀懂到底是什麼意思,後來的時候發現最重要的一點,主人公到另一個班級去兩個班的分數都會變高,然後就簡單了。

//6969 Average Score 

#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
double n1,n2,a[60],b[60],avg1=0,avg2=0;
cin>>n1>>n2;
n1-=1;
for(int i=0;i<n1;i++)
{
cin>>a[i];
avg1+=a[i];
}
avg1/=n1;
for(int i=0;i<n2;i++)
{
cin>>b[i];
avg2+=b[i];
}
avg2/=n2;
int ans1=avg1,ans2=avg2+1;
if(avg1-ans1==0)
ans1-=1;
cout<<ans2<<" "<<ans1<<endl;

}
return 0;

}


Information Entropy

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

Information Theory is one of the most popular courses in Marjar University. In this course, there is an important chapter about information entropy.

Entropy is the average amount of information contained in each message received. Here, a message stands for an event, or a sample or a character drawn from a distribution or a data stream. Entropy thus characterizes our uncertainty about our source of information. The source is also characterized by the probability distribution of the samples drawn from it. The idea here is that the less likely an event is, the more information it provides when it occurs.

Generally, "entropy" stands for "disorder" or uncertainty. The entropy we talk about here was introduced by Claude E. Shannon in his 1948 paper "A Mathematical Theory of Communication". We also call it Shannon entropy or information entropy to distinguish from other occurrences of the term, which appears in various parts of physics in different forms.

Named after Boltzmann's H-theorem, Shannon defined the entropy Η (Greek letter Η, η) of a discrete random variable X with possible values {x1, x2, ..., xn} and probability mass function P(X) as:

H(X)=E(ln(P(x)))

Here E is the expected value operator. When taken from a finite sample, the entropy can explicitly be written as

H(X)=i=1nP(xi)log b(P(xi))

Where b is the base of the logarithm used. Common values of b are 2, Euler's number e, and 10. The unit of entropy is bit for b = 2, nat for b = e, and dit (or digit) for b = 10 respectively.

In the case of P(xi) = 0 for some i, the value of the corresponding summand 0 logb(0) is taken to be a well-known limit:

0log b(0)=limp0+plog b(p)

Your task is to calculate the entropy of a finite sample with N values.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains an integer N (1 <= N <= 100) and a string S. The string S is one of "bit", "nat" or "dit", indicating the unit of entropy.

In the next line, there are N non-negative integers P1P2, .., PNPi means the probability of the i-th value in percentage and the sum of Pi will be 100.

Output

For each test case, output the entropy in the corresponding unit.

Any solution with a relative or absolute error of at most 10-8 will be accepted.

Sample Input

3
3 bit
25 25 50
7 nat
1 2 4 8 16 32 37
10 dit
10 10 10 10 10 10 10 10 10 10

Sample Output

1.500000000000
1.480810832465
1.000000000000


這個是一道公式題,計算的時候要注意精確,同時,所有數的和是100,所以不用把它們相加求和,直接除就可以,還有符號也要注意,0的話爲0.

//6977 Information Entropy


#include<iostream>
#include<cstring>
#include<stdio.h>
#include<cmath>
const double esp = 1e-9;
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
string s;
double b,ans=0,x;
cin>>n>>s;
if(s[0]=='b')
b=2;
else if(s[0]=='n')
b=exp(1.0);
else 
b=10;
while(n--)
{
cin>>x;
if(fabs(x)>esp)
{
x/=100;
ans+=-x*log(x)/log(b);
}

}
printf("%.12lf\n",ans);
}
return 0;


Domination

Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge

Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess with his friends. What's more, he bought a large decorative chessboard with Nrows and M columns.

Every day after work, Edward will place a chess piece on a random empty cell. A few days later, he found the chessboard was dominated by the chess pieces. That means there is at least one chess piece in every row. Also, there is at least one chess piece in every column.

"That's interesting!" Edward said. He wants to know the expectation number of days to make an empty chessboard of N × M dominated. Please write a program to help him.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

There are only two integers N and M (1 <= NM <= 50).

Output

For each test case, output the expectation number of days.

Any solution with a relative or absolute error of at most 10-8 will be accepted.

Sample Input

2
1 3
2 2

Sample Output

3.000000000000
2.666666666667



這道題是概率dp的題目,給出棋盤規格求期望,用三維的來計算。計算的時候比較繁雜,需要注意。同時我們掛題的oj一直沒辦法通過,但是在zoj上是ac的,不理解爲什麼。。。


#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
double dp[2550][55][55];
int main()
{
int t;
cin>>t;
while(t--)
{
int a,b;
cin>>a>>b;
memset(dp,0,sizeof(dp));
for(int i=a*b-1;i>-1;i--)
{
for(int j=a;j>-1;j--)
{
for(int k=b;k>-1;k--)
{
if(k==b&&j==a)
continue;
if(j*k<i)
continue;//不可能的情況 
double a1,a2,a3,a4;
a1=1.0*(j*k-i)/(a*b-i)*1.0;//落在原來行列就有子的地方 
a2=1.0*(b-k)*j/(b*a-i)*1.0;//落在行有列沒有的地方
a3=1.0*(a-j)*k/(a*b-i)*1.0;//類似於上
a4=1.0*((a-j)*(b-k))/(a*b-i); 
dp[i][j][k]=a1*dp[i+1][j][k]+a2*dp[i+1][j][k+1]+a3*dp[i+1][j+1][k]+a4*dp[i+1][j+1][k+1]+1;
}
}
}
printf("%.12lf\n",dp[0][0][0]);
}
return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章