UValive4195 Heroes of Money and Magic

Source: Internet
Author: User

Slope optimization

Want to Curse, Maggi last tune for half an hour

The man who made the data in the TMD is SB.

I write while (scanf ("%d%d", &n,&m)!=eof&&n)

And then on the TMD infinite wa ... WA ... WA ...

scanf ("%d%d", &n,&m), N)

It's over, it's over!!!

Rue de Vaugirard, it's a waste of my time, isn't it, Pit daddy?

1#include <cstdio>2#include <cstdlib>3#include <iostream>4#include <string>5#include <cstring>6 #defineClear (x,i) memset (x,i,sizeof (x))7 #defineRe (I,L,R) for (int i= (l); i<= (R); i++)8 #defineRre (i,r,l) for (int i= (r); i>= (l); i--)9 using namespacestd;TenTemplate <typename q> One voidInin (Q &ret) A { -ret=0;intf=0;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=1; ch=GetChar ();} the      while(ch>='0'&&ch<='9') ret= (ret<<3) + (ret<<1) +ch-'0', ch=GetChar (); -ret=f?-Ret:ret; - } - intn,m,a[5010],sum[5010],cost[5010],x[5010][2],y[5010][2],num[2]; + intf[5010][2],c; - intCrossintAintBintXxintyy) + { A     return(X[b][c]-x[a][c]) * (Yy-y[a][c])- at(Xx-x[a][c]) * (y[b][c]-y[a][c]); - } - intMain () - { -      while(SCANF ("%d%d",&n,&m), N) -     { inm++; -          for(intI=1; i<=n;i++) to         { +scanf"%d",&a[i]); -sum[i]=sum[i-1]+A[i]; thecost[i]=cost[i-1]+sum[i-1]*A[i]; *         } $num[1]=0;Panax NotoginsengC=1; -x[1][1]=y[1][1]=0; the          for(intj=1; j<=m;j++) +         { Ac^=1; thenum[c]=0; +              for(intI=1, k=1; i<=n;i++) -             { $                  while(k<num[!c]&& (x[k+1][!C]-X[K][!C]) *sum[i]>y[k+1][!C]-Y[K][!C]) k++; $f[i][c]=-sum[i]*x[k][!c]+y[k][!c]+Cost[i]; -                 intxx=sum[i],yy=f[i][c]+xx*xx-Cost[i]; -                  while(1<num[c]&&cross (num[c]-1, Num[c],xx,yy) <=0) num[c]--; thex[++num[c]][c]=xx; -y[num[c]][c]=yy;Wuyi             } the         } -printf"%d\n", F[n][c]); Wu     } -     return 0; About}

UValive4195 Heroes of Money and Magic

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.