牡丹江赛区两道水题A I。

38 篇文章 0 订阅
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 A1, A2, .., AN-1 representing the scores of other students in Bob's class.

The last line contains M integers B1, B2, .., 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
签到题没啥好说的,这个人在重点班拖低了重点班的平均分,但是让他去普通班却能提高普通班的平均分,问这个人的得分上下限为多少,且得分为整数。
很简单,算重点班N-1个人的平均分,和普通班M个人的平均分,然后注意上下取整问题就好,不过当N-1的平均分恰好为整数时,这个时候不是取整而是-1,同理M个人的平均分
是整数时也不是取整,而是直接+1,然后就没有然后A了咯。。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{

    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        int sum1=0,sum2=0;
        int a[105];
        int  b[105];
        cin>>n>>m;
        for(int i=0;i<n-1;i++)
        {

            cin>>a[i];
            sum1+=a[i];
        }
        for(int i=0;i<m;i++)
        {

            cin>>b[i];
            sum2+=b[i];
        }
      //  cout<<sum1<<" "<<sum2<<endl;
        int ans1;
        int ans2;
        if(sum2%m==0)
        {
            ans1=sum2/m+1;
        }
        else
        {
            ans1=(int)(ceil)(sum2*1.0/m);
        }
        if(sum1%(n-1)==0)
        {
            ans2=sum1/(n-1)-1;

        }
        else
        {
            ans2=ans2=sum1/(n-1);
        }
        //int ans2=(sum1/(n-1));
       // cout<<ans1<<" "<<ans2<<endl;
        int sum=ans1+ans2;
        int res=min(ans1,ans2);
        cout<<res<<" "<<sum-res<<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:

\Large 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

\Large H(X)=-\sum_{i=1}^{n}P(x_i)\log_{~b}(P(x_i))

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:

\Large 0 \log_{~b}(0) = \lim_{p \to 0 +} p \log_{~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 P1, P2, .., PN. Pi 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

也很简单(理解了题意的情况下),就是求HX,然后这里的PX代表数量,所以除以100转换成概率,否则你那个计算公式显然累加起来是负的答案是正的怎么可能咧,然后就是
这题非常仁慈的告诉了你有0该怎么处理,用洛必达法则求个极限就知道极限为0了吧,所以0就可以忽略不计,然后根据字符串来确定底数为多少,进行累加就OK了。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
const double e=exp(1.0);
using namespace std;

int main()
{
    //printf("%.10lf\n",e);

    int t;
    cin>>t;
    while(t--)
    {
        int n;
        string s;
        cin>>n>>s;
        double p[105];
        double a[105];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            p[i]=(a[i]*1.0)/100;
        }
        double ans=0.0;
        if(s=="bit")
        {
            for(int i=0;i<n;i++)
            {
                if(p[i]!=0.0)
                {
                    ans+=p[i]*(log2)(p[i]);
                }
            }
        }
        else if(s=="nat")
        {
            for(int i=0;i<n;i++)
            {
                if(p[i]!=0.0)
                {
                    ans+=p[i]*log(p[i]);
                }
            }
        }
        else if(s=="dit")
        {
             for(int i=0;i<n;i++)
            {
                if(p[i]!=0.0)
                {
                    ans+=p[i]*(log10)(p[i]);
                }
            }
        }
        printf("%.10lf\n",-ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值