2013 ACM区域赛长沙 A Alice’s Print Service HDU 4791
题意:就是一个打印分段收费政策,印的越多,单张价格越低,输入需要印刷的数量,求最小印刷费用一个细节就是,比当前还小的状态可能是最后几个。
1 #include<stdio.h> 2 #include<string.h> 3 #include<cstdio> 4 #include<string> 5 #include<math.h> 6 #include<algorithm> 7 #include<iostream> 8 #define LL long long 9 #define PI atan(1.0)*4 10 #define DD double 11 #define MAX 200200 12 #define mod 100 13 #define dian 1.000000011 14 #define INF 0x3f3f3f 15 #define clc(a,b) memset(a,b,sizeof(a)) 16 using namespace std; 17 const int maxn=100010; 18 LL s[maxn],p[maxn],c[maxn]; 19 LL minn[maxn];//记录i之后最小的s*p,不包括当前i状态 20 int main() { 21 // freopen("inn.txt","r",stdin); 22 int T; 23 scanf("%d",&T); 24 while(T--) { 25 int n,m; 26 LL ans=0; 27 clc(s,0); 28 clc(p,0); 29 clc(c,0); 30 scanf("%d%d",&n,&m); 31 for(int i=0; i<n; i++) { 32 scanf("%I64d%I64d",&s[i],&p[i]); 33 c[i]=s[i]*p[i]; 34 } 35 LL minx=c[n-1]; 36 minn[n-1]=c[n-1]; 37 for(int i=n-2;i>=0;i--){ 38 if(c[i+1]<minx){ 39 minx=c[i+1]; 40 minn[i]=minx; 41 } 42 else{ 43 minn[i]=minx; 44 } 45 } 46 while(m--) { 47 LL q; 48 scanf("%I64d",&q); 49 int pos=upper_bound(s,s+n,q)-s; 50 if(pos==n){ 51 printf("%lld\n",q*p[n-1]); 52 continue; 53 } 54 if(pos==0) ; 55 else 56 pos=pos-1; 57 LL pri=p[pos]*q; 58 if(pri>minn[pos]) 59 ans=minn[pos]; 60 else 61 ans=pri; 62 printf("%lld\n",ans); 63 } 64 } 65 return 0; 66 }