当前位置:网站首页>P1023 tax and subsidy problems (number theory & inequality)

P1023 tax and subsidy problems (number theory & inequality)

2021-08-10 08:04:41 wx6110fa547fd20

P1023 Tax and subsidy issues ( number theory & inequality )

  Subject portal

The question : Given the expected price , Find the minimum absolute value of subsidy or tax at this price to maximize its total profit .(PS: The topic is really beautiful )

Ideas : It seems that the inputs are arranged in ascending price order by default , So calculate the sales volume at all prices , Then traverse from the cost price to the highest price that can be reached , Violence calculates ans The scope of the [mn,mx] Discuss mn,mx Positive and negative .

AC Code :

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],ept,pr,cb,sum,now=0,b; //ept (expect) Expect price  pr(price) cb( cost ) sum( Sales volume ) now( Current price ) 
int main(){  //b( Linearly decreasing sales  
	cin>>ept>>pr>>sum,cb=pr;
	while(pr!=-1&&sum!=-1){ // The default price is given in ascending order . 
		a[pr]=sum;
		for(int i=now+1;i<pr;i++)
			a[i]=a[i-1]+(sum-a[now])/(pr-now);// Calculate the sales volume at all prices . 
		now=pr;
		cin>>pr>>sum;
	}
	cin>>b;
	while(a[now]>b)// Calculate the decreasing sales volume after the highest price . 
		now++,a[now]=a[now-1]-b;
	double mx=1e9,mn=-1e9; 
	for(int i=cb;i<=now;i++){
		int jg=a[i]-a[ept];
		if(jg){
		double ans=((ept-cb)*a[ept]-(i-cb)*a[i])*1.0/jg;//ans Express subsidy  
		if(jg>0) mx=min(mx,ans);// Judge whether the symbol is positive   If it is a regular representation  ans<= , It is ans>= 
		else if(jg<0) mn=max(mn,ans);
		}	
	}
	if(mn>mx) puts("NO SOLUTION");
	else if(mn>0) printf("%d\n",(int)ceil(mn));
	else if(mx<0) printf("%d\n",(int)floor(mx));
	else puts("0");
	return 0;
} 

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.

版权声明
本文为[wx6110fa547fd20]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/08/20210810080205581n.html

随机推荐