CSP 2016-12-2 工资计算

思路:

分段函数+遍历

即:

用分段函数计算原有工资加税后的工资,并与题目给定的工资比较。

暴力枚举范围为t~2t

 

c++代码如下:

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

double zero = 1e-6;

double wage(int s)
{
	double res = s;
	int a = s - 3500;
	if (a <= 0) return res;

	if (a <= 1500){
		res -= a * 0.03;
	}
	else res -= 1500 * 0.03;
	int a2 = max(0, min(a - 1500, 4500 - 1500));
	res -= a2 * 0.10;
	int a3 = max(0, min(a - 4500, 9000 - 4500));
	res -= a3 * 0.20;
	int a4 = max(0, min(a - 9000, 35000 - 9000));
	res -= a4 * 0.25;
	int a5 = max(0, min(a - 35000, 55000 - 35000));
	res -= a5 * 0.30;
	int a6 = max(0, min(a - 55000, 80000 - 55000));
	res -= a6 * 0.35;
	int a7 = max(0, a - 80000);
	res -= a7 * 0.45;
	return res;
}

int main()
{
	int t;
	cin >> t;
	for (int i = t; i < 2 * t; i++){
		if (abs(wage(i) - t) < zero){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值