标签:title ram article ott bin sample 无限 certainly targe
1 program rrr(input,output); 2 var 3 n,m,i,h,t:longint; 4 q:array[0..500050]of longint; 5 f,s:array[0..500050]of int64; 6 function up(j,k:int64):int64; 7 begin 8 exit(f[j]-f[k]+sqr(s[j])-sqr(s[k])); 9 end; 10 function down(j,k:int64):int64; 11 begin 12 exit((s[j]-s[k])<<1); 13 end; 14 begin 15 assign(input,‘r.in‘);assign(output,‘r.out‘);reset(input);rewrite(output); 16 while not eof do 17 begin 18 readln(n,m); 19 s[0]:=0; 20 for i:=1 to n do begin readln(s[i]);s[i]:=s[i]+s[i-1]; end; 21 h:=1;t:=1;q[1]:=0;f[0]:=0; 22 for i:=1 to n do 23 begin 24 while (h<t) and (up(q[h+1],q[h])<=s[i]*down(q[h+1],q[h])) do inc(h); 25 f[i]:=f[q[h]]+sqr(s[i]-s[q[h]])+m; 26 while (t>h) and (up(i,q[t])*down(q[t],q[t-1])<=up(q[t],q[t-1])*down(i,q[t])) do dec(t); 27 inc(t);q[t]:=i; 28 end; 29 writeln(f[n]); 30 end; 31 close(input);close(output); 32 end.
这代码一开始没用int64无限WA,后来改了int64才AC了,但我看网上c++代码没开longlong啊,不知道怎么回事。
hdu3507 Print Article(斜率优化入门)(pascal)
标签:title ram article ott bin sample 无限 certainly targe
原文地址:http://www.cnblogs.com/Currier/p/6607163.html