zoukankan      html  css  js  c++  java
  • 洛谷P1023税收(题意,模拟)

    题目链接:https://www.luogu.org/problemnew/show/P1023

    感觉这题就是语文式阅读+数学式计算,真无奈唉。。

    这道题有2大关键:

    一:读题,能明白它是什么意思,超关键泪奔~~

    二:计算求解,好像是列多个方程求解,我数学不好所以这里就用暴力的方法代替了(听说数据都小于10000...)。。

    好了,这题的意思就是对所有可能的价格+一个数i或-一个数i形成新的价格(利润),可以使得当预期价格时,利润为最大!(由于价格销售量都是线性变化的,所以当上升到一个最高点下降后,后面肯定一直下降。所以可以简化为求一个山峰型的,判断中间在三者中是否最大,即预期价格前一个<预期价格利润>预期价格后一个)

      1 #include <iostream>
      2 #include <string>
      3 #include <algorithm>
      4 #include <iomanip>
      5 #include <cstdio>
      6 #include <cstring>
      7 #include <cmath>
      8 using namespace std;
      9 typedef long long ll;
     10 typedef unsigned long long ull;
     11 const int maxn=1e6+5;
     12 const int maxm=1005;
     13 const int inf=1e9;
     14 int a[maxn];
     15 struct px
     16 {
     17     int jiage;
     18     int xiaoshou;
     19 }T[maxn];
     20 
     21 int main()
     22 {
     23     ios::sync_with_stdio(false); cin.tie(0);
     24 
     25     int yuqi,chengben,chengbens;
     26     cin>>yuqi;
     27     cin>>chengben>>chengbens;
     28     int p=1,g=0;
     29     for(p=1;;p++)
     30     {
     31         int x,y;
     32         cin>>x>>y;
     33         if(x==-1 && y==-1) break;
     34         T[p].jiage=x;
     35         T[p].xiaoshou=y;
     36 
     37         if(T[p].jiage==yuqi) g=p;
     38     }
     39     int m;
     40     cin>>m;
     41 
     42     p--;
     43     int f=p+1;
     44 
     45     //开始前奏处理
     46     if(T[p].jiage>yuqi && !g)//输入中没有预期价格,且输入价格比预期大很多时的处理
     47     {
     48         int e=0;
     49         for(int i=1;i<=p;i++)
     50         {
     51             if(T[i].jiage<yuqi)
     52             {
     53                 T[p].jiage=T[i].jiage;
     54                 T[p].xiaoshou=T[i].xiaoshou;
     55                 e++;
     56             }
     57         }
     58         if(!e)//(所有都比预期大时)干脆从预期开始重新赋值(既然它比前后都大,而后面又都是递减的,所以就算与最后一个比也不影响)
     59         {
     60             T[p].jiage=chengben;
     61             T[p].xiaoshou=chengbens;
     62         }
     63     }
     64     for(int i=T[p].jiage+1;i<=10001;i++)//(所有都比预期小时)将可能的最大价格及销量进行处理
     65     {
     66         T[f].jiage=i;
     67         T[f].xiaoshou=T[p].xiaoshou-m*(T[f].jiage-T[p].jiage);//线性变化
     68         f++;
     69     }
     70     if(!g)//输入中没有预期价格时(都小或都大),寻找处理后的预期价格位置
     71     {
     72         for(int i=p;i<=10001;i++)
     73         {
     74             if(T[i].jiage==yuqi)
     75             {
     76                 g=i;
     77                 break;
     78             }
     79         }
     80     }
     81 
     82 
     83     //处理完毕,正式计算
     84     for(int i=1;i<=10001;i++)//补贴
     85     {
     86         int a=(T[g].jiage-chengben+i)*T[g].xiaoshou;
     87         int b=(T[g-1].jiage-chengben+i)*T[g-1].xiaoshou;
     88         int c=(T[g+1].jiage-chengben+i)*T[g+1].xiaoshou;
     89         if(a>b && a>c) { cout<<i<<endl; return 0; }
     90     }
     91     for(int i=1;i<=10001;i++)//收税
     92     {
     93         int a=(T[g].jiage-chengben-i)*T[g].xiaoshou;
     94         int b=(T[g-1].jiage-chengben-i)*T[g-1].xiaoshou;
     95         int c=(T[g+1].jiage-chengben-i)*T[g+1].xiaoshou;
     96         if(a>=b && a>=c) { cout<<'-'<<i<<endl; return 0; }
     97     }
     98     cout<<"NO SOLUTION"<<endl;//无解
     99 
    100     return 0;
    101 }

    完。

  • 相关阅读:
    codevs 1164 统计数字
    codevs 2597 团伙
    codevs 1472 体检
    Openjudge 1.13-21:最大质因子序列
    Openjudge 1.13-23:区间内的真素数
    codevs 1388 砍树
    codevs 1536 海战
    codevs 3110 二叉堆练习3
    codevs 2879 堆的判断
    Openjudge 1.13.37:乒乓球
  • 原文地址:https://www.cnblogs.com/redblackk/p/9741402.html
Copyright © 2011-2022 走看看