网站建设属于哪种职位,科技有限公司的名称应该怎么取名,网站搭建免费官网,电影资源分享网站怎么做的斜率优化错误总结 网上说很多OJ桑的斜率优化大多都是模板题- -#xff0c;结果每次都跪Orz。。。在此总结一些常见错误#xff1a; 1#xff1a;不得不说斜率优化很多时候计算式很长- -#xff0c;代码容易错细节- -。 2#xff1a;其次就是弹队头以及弹队尾的时候大小关系… 斜率优化错误总结 网上说很多OJ桑的斜率优化大多都是模板题- -结果每次都跪Orz。。。在此总结一些常见错误 1不得不说斜率优化很多时候计算式很长- -代码容易错细节- -。 2其次就是弹队头以及弹队尾的时候大小关系容易错关键是除负数时要变号 弹的时候边界要弄好总的来说很多斜率优化都很像推式子——边弹边做边入队 3再者就是一些先后问题 在处理队列的时候尤其是弹队尾的时候如果有推导式中有未知量要先计算不然会弹WA- - 4还有队列初始化问题- -要机智点- - 代码 1锯木厂选址CEOI2004试题 1 #includecstdio2 int n,f1,r,top1,tai1,ans888888888,c[20010],w[20010],d[20010],s[20010];3 int all(int a,int b){return c[b]-c[a]-w[a-1]*(d[b]-d[a]); }4 double k(int a,int b){return (double)(w[a]*d[a]-w[b]*d[b])/(double)(w[a]-w[b]);}5 int main(){6 scanf(%d,n); s[1]1;7 for (int i1; in ; i) scanf(%d%d,w[i],d[i1]);8 for (int i2; in1; i) w[i] w[i-1];9 for (int i2; in1; i) c[i] c[i-1]w[i-1]*d[i] ;
10 for (int i2; in1; i) d[i] d[i-1];
11 for (int i2; in; i){
12 while (top taik(s[top],s[top1]) d[ i ] ) top;
13 while (toptaik(s[tai-1],s[tai])k(s[tai],i)) tai--;
14 r c[ s[top] ] all(s[top]1,i) all(i1,n1);
15 if (rans) ansr; s[tai]i;
16 } printf(%d,ans);
17 } 锯木厂选址CEOI2004 2玩具装箱 HNOI2008试题 1 #includecstdio2 long long top0,tai0,s[50010],f[50010],n,l,K,h[50010];3 long double k(int a,int b) {4 return (long double)(f[b]h[b]*h[b]-f[a]-h[a]*h[a])5 /(long double)(h[b]-h[a]);6 }7 int main(){8 scanf(%lld%lld,n,l);9 for (int i1; in; i) scanf(%lld,h[i]);
10 for (int i1; in; i) h[i]h[i-1]1;
11 for (int i1; in; i) {
12 Kh[i]-1-l;
13 while (top taik(s[top],s[top1])2*K) top;
14 f[i]f[s[top]](K-h[s[top]])*(K-h[s[top]]);
15 while (toptaik(s[tai-1],s[tai])k(s[tai],i)) tai--;
16 s[tai]i;
17 } printf(%lld,f[n]);
18 } 玩具装箱 HNOI2008 3土地并购 USACO精选49 1 #includecstdio2 #includealgorithm3 struct p{long long a,b;}t[50010];4 long long l,n,top0,tai0,f[50010],s[50010];5 bool cmp(const px,const py) {return (x.ay.a)||(x.ay.ax.by.b);}6 long double k(long long j1,long long j2 ) {7 return (long double)(f[j1]-f[j2])/8 (long double)(t[j21].b-t[j11].b);9 }
10 int main(){
11 scanf(%lld,n);
12 for (int i1; in; i) scanf(%lld%lld,t[i].a,t[i].b);
13 std::sort(t1,tn1,cmp);
14 for (int i1; in; i) {
15 while (lt[i].bt[l].b) l--;
16 t[l].at[i].a;
17 t[ l].bt[i].b;
18 }
19 for (int i1; il; i) {
20 while (top taik(s[top],s[top1]) t[ i ].a ) top;
21 f[i]f[s[top]]t[i].a*t[s[top]1].b;
22 while (toptaik(s[tai-1],s[tai])k(s[tai],i)) tai--;
23 s[tai]i;
24 } printf(%lld,f[l]);
25 } 土地并购USACO精选49 转载于:https://www.cnblogs.com/qq359084415/p/3435350.html