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

收入税挑战
本文介绍了一个特殊的国家中的收入税计算问题,对于给定的工资范围,需要计算支付的平均收入税额。通过数学推导和编程实现,解决了不同工资水平下的期望税收计算。
Income Tax Hazard II
Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Download as PDF

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;
}



转载于:https://www.cnblogs.com/cszlg/archive/2012/08/21/2910485.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值