P1023 Tax and subsidy issues

topic background

The lower the price of each item, the higher its sales. Now the cost of a commodity and its sales volume at several price points (the product will not be sold below cost) are known, and it is assumed that the change in sales between adjacent price points is linear and after the price is higher than the given maximum price, Sales decrease by a fixed value. (We assume the price and the sales volume are both integers)

For some special commodities, it is impossible to completely adjust their prices by the market. At this time, the government needs to control it in the form of taxes or subsidies. (The so-called tax or subsidy is a fixed amount of currency charged or given to the manufacturer for each product)

Topic description

You're a project manager at a consulting firm, and now you know the government's expected price for a certain commodity, and how it's selling at various price points. You are required to determine the minimum amount (also a whole number) that the government owes a tax or a subsidy on this item, so that the merchant can obtain the maximum total profit at such a price expected by the government relative to other prices.

Total profit = unit product profit * sales volume

Profit per unit of commodity = price of unit commodity - cost of unit commodity (- tax or + subsidy)

Input and output format

Input format:

The first line of input is the government's expected price for a certain commodity, the second line has two integers, the first integer is the cost of the commodity, and the second integer is the sales volume when it is sold at the cost price. There are two integers, the first is the unit price at a certain price, and the second is the sales volume at this time. A line of -1, -1 indicates that all known prices and corresponding sales have been entered, and the last line entered is a separate line. The integer represents the decrease in sales for each dollar of increase in the known maximum unit price.

Output format:

The output has two cases: if the maximum total profit can be obtained at the government's expected price, a single integer is output. The positive or negative of the number indicates whether it is a subsidy or a tax, and the size of the number indicates the minimum amount of the subsidy or tax. If there are multiple solutions, take the output with the smallest absolute value.

If the maximum total profit cannot be obtained at the government's expected price, output "NO SOLUTION".

Input and output example

Input Example #1: Copy
31
28 130
30 120
31 110
-1  -1
15
Output Sample #1: Copy
4

illustrate

All numbers are less than 100000

 

Solution:

  Another nasty violent simulation problem.

  直接处理出所有可能的价格情况,然后判断标准价格的购买量,最后就是从小到大暴力枚举补贴和收税的情况,注意一些细节输出就好了。(详见代码)

  洛谷数据还是很水的~~我没想到什么好方法判断无解的情况,所以直接忽略了就提交,结果$AC$了。

代码:

 

 1 #include<bits/stdc++.h>
 2 #define For(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
 3 #define il inline
 4 using namespace std;
 5 const int N=100005;
 6 il int gi(){
 7     int a=0;char x=getchar();bool f=0;
 8     while((x<'0'||x>'9')&&x!='-')x=getchar();
 9     if(x=='-')x=getchar(),f=1;
10     while(x>='0'&&x<='9')a=a*10+x-48,x=getchar();
11     return f?-a:a;
12 }
13 int sdc,sdn,cut,ww,ll,cnt;
14 struct node{
15     int c,num;
16     bool operator<(const node a)const{return num>a.num;}
17 }a[N];
18 il void solve(){
19     int ans=0,p,q,x,y;
20     bool f1=0,f2=0;
21     while(1){
22         f1=0,f2=0;
23         p=(sdc-a[1].c+ans)*sdn;
24         q=(sdc-a[1].c-ans)*sdn;
25         For(i,1,cnt){
26             if(a[i].num<=0)break;
27             x=(a[i].c-a[1].c+ans)*a[i].num;y=(a[i].c-a[1].c-ans)*a[i].num;
28             if(x>p)f1=1;
29             if(y>q)f2=1;
30             if(f1&&f2)break;
31         }
32         if(f1&&f2){ans++;continue;}
33         x=a[cnt].c,y=a[cnt].num;
34         while(y>0){
35             x++;y-=cut;
36             if((x-a[1].c+ans)*y>p)f1=1;
37             if((x-a[1].c-ans)*y>q)f2=1;
38             if(f1&&f2)break;
39         }
40         if(f1&&!f2){cout<<-ans;return;}
41         if(!f1&&f2){cout<<ans;return;}
42         if(!f1&&f2){cout<<ans;return;}
43         ans++;
44     }
45 }
46 int main(){
47     sdc=gi();
48     int x,y;
49     while(1){
50         x=gi(),y=gi();
51         if(x==-1&&y==-1)break;
52         a[++cnt].c=x,a[cnt].num=y;
53     }
54     cut=gi();
55     sort(a+1,a+cnt+1);
56     ll=a[2].num-a[1].num;
57     For(i,1,cnt-1) if(a[i+1].c-a[i].c>1)
58         For(j,a[i].c+1,a[i+1].c-1)
59         a[++cnt].c=j,
60         a[cnt].num=a[i].num-(a[i].num-a[i+1].num)/(a[i+1].c-a[i].c)*(j-a[i].c);
61     sort(a+1,a+cnt+1);
62     x=0;
63     For(i,1,cnt)if(a[i].c==sdc){x=1,sdn=a[i].num;break;}
64     if(!x)sdn=a[cnt].num-(sdc-a[cnt].c)*cut;
65     solve();
66     return 0;
67 }

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325856936&siteId=291194637