Income Tax Hazard (II) (数学,难)

Income Tax Hazard II
Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit  Status  Practice  UVA 11667

Description

Problem B
Income Tax Hazard (II) 
Input: 
Standard Input

Output: Standard Output

 

The word tax makes us unhappy and if it is income tax it saddens us even more (have you ever wondered why many rich people leave their own country and stay in Switzerland). The strangest thing is that in many countries and states one has to pay income tax as well as sales tax.

 

Now you are in a strange new country, whose income tax structure is almost unknown to you. The things that you know about the salary/tax structure of this country are given below:

 

  1. Salary is always an integer but income tax may or may not be integer. Your salary is denoted withM.
  2. There are two slabs for income tax denoted by two integers S1 and S2. You have to pay 10% income tax for salary part above S1 and below (S2).
  3. You don’t have to pay any income tax for the salary below S1.
  4. For salary portion above S2 you will have to pay 20% income tax. So if S1=50000 and S2=100000 and your salary is 120000, then your total income tax will be 50000*0.10+20000*0.20=9000.
  5. The problem is, you don’t know the value of S1 and S2. Only thing you know is that the value of S1 and S2 is within two given integer values min and max (inclusive) and S1<=S2.

 

Now given the values of minmax and M you have two find the expected amount of income tax that you need to pay. You should assume that all distinct combinations of S1 and S2 satisfying the above conditions are equally likely.

 

Input

The input file contains around 10000 line of input. Each line contains three integers M (0 < M ≤ 400000)min and max (50000 ≤ min ≤ max ≤ 200000). Their meaning is given in the problem statement above. Input will be terminated with three zeroes in a single line.

Output

For each line of input produce one line of output. This line contains the serial of output followed by a floating-point number which denotes the expected amount of income. This floating-point number should be rounded to two digits after decimal point.

Sample Input                              Output for Sample Input

10000 50000 50002

70000 50000 80000

0 0 0

 

Case 1: 0.00

Case 2: 1333.36

Problem Setter: Shahriar Manzoor

Special Thanks: Derek Kisman

 求的是tax的期望

//Memory: 0 KB		Time: 556 MS
//Language: C++ 4.1.2		Result: Accepted

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int m, max, min, T = 1;
    double s1, s12;
    double tax1, tax2, tax;
    while(scanf("%d %d %d", &m, &min, &max) && m)
    {
        if(m <= min) tax = 0.0;
        else if(m >= max)
        {
            //s1 <= s2 <= m,此时tax = (s2-s1)*0.1+(m-s2)*0.2 = 0.2*m-0.1*(s1+s2),
            //故此只要求出(s1+s2)的期望s12即可
            s12 = 0.0;
            for(int i = min; i <= max; i++)
            {
                s12 = s12 + 0.5 * (3 * i + max) * (max - i + 1);
            }
            //v是(s1,s2)的组合数,本来应该是用int型的,但是由于用long long
            //也存在溢出的风险,所以此处求出的v实际上是组合数的十分之一
            double v = 0.05 * (max - min + 2) * (max - min + 1);
            s12 /= v;
            tax = 0.2 * m - 0.01 * s12;
        }
        else
        {
            //s1 <= m <= s2,此时tax = (m - s1)*0.1,只需求出s1的期望即可
            s1 = 0.5 * (min + m);
            tax1 = (m - s1) * 0.1;
            //u是(s1,s2)的组合数,本来应该是用int型的,但是由于用long long
            //也存在溢出的风险,所以此处求出的v实际上是组合数的十分之一
            double u = 0.1 * (m - min + 1) * (max - m + 1);
            //s1 <= s2 < m,此时tax = (s2-s1)*0.1+(m-s2)*0.2 = 0.2*m-0.1*(s1+s2),
            //故此只要求出(s1+s2)的期望s12即可
            s12 = 0.0;
            for(int i = min; i < m; i++)
            {
                s12 = s12 + 0.5 * (3 * i + m - 1) * (m - i);
            }
            //v是(s1,s2)的组合数,本来应该是用int型的,但是由于用long long
            //也存在溢出的风险,所以此处求出的v实际上是组合数的十分之一
            double v = 0.05 * (m - min + 1) * (m - min);
            s12 /= v;
            tax2 = 0.2 * m - 0.01 * s12;
            tax = (tax1 * u + tax2 * v) / (0.5 * (max - min + 2) * (max - min + 1)) * 10;
        }
        printf("Case %d: %.2lf\n", T++, tax);
    }
    return 0;
}



你可能感兴趣的:(Integer,input,each,setter,structure,combinations)