P1023 税收与补贴问题 (模拟)

题目链接

Solution

比较恶心的模拟题(主要是难看懂题意其实)
题意戳这里
然后根据一些简单的数学常识,可以知道这是一个二次函数.
所以我们每次枚举一个值,然后判定政府给出的价格是否是顶点即可.
与其少一块钱和多一块钱比较即可.

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn=110008;
int w[maxn],c[maxn];
int to,num,v,maxx;;

int read()
{
    int f=1,w=0; char ch=getchar(); 
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){w=w*10+ch-'0';ch=getchar();}
    return f*w;
}

void pre()
{
    int fuck=(c[w[2]]-c[w[1]])/(w[2]-w[1]);
    for(int i=w[1];i<=to+100;i++)
    {
        if(!c[i])
        {
            if(i<=maxx)
                c[i]=c[w[1]]+fuck*(i-w[1]);     
            else
                c[i]=c[maxx]-v*(i-maxx);
        }
        //cout<<i<<' '<<c[i]<<endl;     
    }
}

bool jud(int x)
{
    int fuck1=c[to-1]*(to-1-w[1]+x);
    int fuck2=c[to]*(to-w[1]+x);
    int fuck3=c[to+1]*(to+1-w[1]+x);
    if(fuck2>=fuck1&&fuck2>=fuck3)return 1;
    else return 0;
}

int main()
{
    scanf("%d",&to);
    while(1)
    {
        int x,y;
        x=read(); y=read();
        if(x==-1&&y==-1)break;
        w[++num]=x;
        c[x]=y;
        maxx=max(maxx,w[num]);
    }
    v=read();
    pre();
    if(jud(0)){cout<<0<<endl;return 0;}
    int ans1=0,ans2=0,fuck1=0,fuck2=0;
    for(int i=1;i<=maxn;i++)
    if(jud(i)){fuck1=1;ans1=i;break;}
    for(int i=-1;i>=-maxn;i--)
    if(jud(i)){fuck2=1;ans2=i;break;}
    if(fuck1||fuck2)
    {
        if(fuck1)
        {
            if(fuck2)
            if(abs(ans2)<ans1)
            {cout<<ans2<<endl;return 0;}
            cout<<ans1<<endl;
        }
        else
        if(fuck2)
        {cout<<ans2<<endl;return 0;}
        else
        cout<<"No Solution"<<endl;
    }
}

转载于:https://www.cnblogs.com/Kv-Stalin/p/9407591.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值