AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

工资计算

作者: 作者的头像   chicali ,  2025-06-06 21:42:35 · 山西 ,  所有人可见 ,  阅读 1


0


这题其实很容易想到二分,虽然我最开始想的是暴力qwq

//二分
#include <iostream>
using namespace std;

int arr[] = {0,1500, 4500, 9000, 35000, 55000, 80000,1000000};
double r[] = {0,0.03, 0.1, 0.2, 0.25, 0.3, 0.35, 0.45};

bool check(double S,int T){     //这边double有点必要,不然可能会导致由于上下取整的问题导致出现伪答案9999(当T = 9255)
    int A = S-3500;
    double tax = 0;
    if(A){
        for(int i=1;i<8;i++){
            if(A>=arr[i]){
                tax += (arr[i]-arr[i-1])*r[i];
            }
            else {
                tax+=(A-arr[i-1])*r[i];
                break;
            }
        }
        S-=tax;
    }
    return S<T;
}

int main(){
    int T;
    cin>>T;
    int l = T,r = 2*T;
    while(l<r){
        int mid = l+r>>1;
        if(check(mid,T)) l = mid+1;
        else r = mid;
    }
    cout<<l<<endl;
    return 0;
}




//暴力
//太暴力了
#include <iostream>
using namespace std;

int main(){
    int T;
    cin>>T;
    T-=3500;
    int base = 3500;
    if(T>=57505){
        cout<<(T+8750+6000+6500+900+300+45-80000*0.45)/(1-0.45)+base<<endl;
    }
    else if(T>=41255){
       cout<<(T+6000+6500+900+300+45-55000*0.35)/(1-0.35)+base<<endl;
    }
    else if(T>=27255){
        cout<<(T+6500+900+300+45-35000*0.3)/(1-0.3)+base<<endl;
    }
    else if(T>=7755){ 
        cout<<(T+900+300+45-9000*0.25)/(1-0.25)+base<<endl;
    }
    else if(T>=4155){  
        cout<<(T+300+45-4500*0.2)/(1-0.2)+base<<endl;
    }
    else if(T>=1455){
        cout<<(T+45-1500*0.1)/(1-0.1)+base<<endl;
    }
    else if(T>=0){
        cout<<T/(1-0.03)+base<<endl;
    }
    else cout<<(T+base)<<endl;
    return 0;

}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息