大模拟、数学题、阅读题(虽然我题意没看懂然后苟了题解QwQ)
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 5 #define ri register int 6 #define inf 2147483647 7 8 using namespace std; 9 10 inline int max(int x,int y){ 11 if(x>y)return x;else return y; 12 } 13 14 inline int min(int x,int y){ 15 if(x<y)return x;else return y; 16 } 17 18 double t; //临时变量 19 int t1,t2; //临时变量 20 int eva; //估价 21 int cost; //成本 22 int maxp; //最高价(销量>0) 23 int num[100005]; //销量 24 int p[100005],cnt=1; //初始价位及计数变量 25 int dec; //超过最高价后的减少值 26 int rat; //相邻价位间销量变化率 27 int maxv=inf,minv=-inf; //答案区间 28 29 int main(){ 30 memset(num,-1,sizeof(num)); 31 scanf("%d",&eva); 32 scanf("%d",&cost); 33 scanf("%d",&num[cost]); 34 p[1]=cost; 35 while(1){ 36 scanf("%d%d",&t1,&t2); 37 if(t1==-1 && t2==-1)break; 38 num[t1]=t2; 39 cnt++; 40 p[cnt]=t1; 41 } 42 scanf("%d",&dec); //输入 43 44 for(ri i=p[cnt]+1;;i++){ 45 t1=num[p[cnt]]-dec*(i-p[cnt]); 46 if(t1<=0){ 47 maxp=i-1; 48 break; 49 } 50 num[i]=t1; 51 } //处理最高价后的部分 52 53 for(ri i=1;i<cnt;i++){ 54 rat=(num[p[i+1]]-num[p[i]])/(p[i+1]-p[i]); 55 for(ri j=p[i]+1;j<p[i+1];j++)num[j]=num[p[i]]+rat*(j-p[i]); 56 } //处理相邻价位间的空缺 57 58 for(ri i=cost;i<=maxp;i++){ 59 if(i==eva)continue; 60 if(((i-cost)*num[i]+(cost-eva)*num[eva])%(num[eva]-num[i])){ 61 t=((i-cost)*num[i]+(cost-eva)*num[eva])*1.0/(num[eva]-num[i]); 62 t1=ceil(t); 63 t2=floor(t); 64 }else t1=t2=((i-cost)*num[i]+(cost-eva)*num[eva])/(num[eva]-num[i]); 65 if(num[eva]-num[i]>0)minv=max(minv,t1); 66 else maxv=min(maxv,t2); 67 } //解不等式组 68 69 if(maxv==inf && minv==-inf)printf("NO SOLUTION "); 70 if(maxv!=inf && minv!=-inf && maxv<minv)printf("NO SOLUTION "); 71 if(maxv!=inf && minv==-inf) 72 if(maxv>=0)printf("0 "); 73 else printf("%d ",maxv); 74 if(maxv==inf && minv!=-inf) 75 if(minv<=0)printf("0 "); 76 else printf("%d ",minv); 77 if(maxv!=inf && minv!=-inf && maxv>=minv) 78 if(minv>=0)printf("%d ",minv); 79 else if(maxv<=0)printf("%d ",maxv); 80 else printf("0 "); 81 82 return 0; 83 }