Bzoj 1597: [Usaco2008 Mar] Land purchase 2011-12-27

Source: Internet
Author: User

1597: [Usaco2008 Mar] Land purchase

Time Limit:10 Sec Memory limit:162 MB
submit:697 solved:244
[Submit] [Status] [Discuss]

Description farmer John prepares to expand his farm, and he is considering N (1 <= n <= 50,000) blocks of rectangular land. The length and width of each land is satisfied (1 <= wide <= 1,000,000; 1 <= long <= 1,000,000). The price of each piece of land is its area, but FJ can buy much faster land at the same time. The price of these lands is their largest length multiplied by their maximum width, but the length of the land cannot be exchanged. If FJ buys a 3x5 land and a 5x3, he needs to pay 5x5=25. FJ wanted to buy all the land, but he found that grouping to buy the land would save money. He needs you to help him find the minimum funds. input* line 1th: one number: N * 2nd. N+1 Line: Line i+1 contains two numbers, respectively, the length and width of block I land output* the first line: the minimum feasible cost. Sample Input4
100 1
15 15
20 5
1 100

Input explanation:

There are 4 pieces of land.

Sample Output
500

HINT


FJ 3 groups to buy these lands: The first group: 100x1, the second group of 1x100, the third group of 20x5 and 15x15 plot. Each group
The price is 100,100,300, a total of 500.

Source

____________________________________________

1 Program Stone;2 varI,j,n,bist,head,tail,insn:longint;3Len,wid,f,que:Array[0..100000] ofInt64;4 Procedure KP (t,w:longint);5  varI,j:longint;6 K,ml,mw:int64;7   begin8i:=t;j:=w;ml:=len[(T+W)Div 2];mw:=wid[(T+W)Div 2];9    RepeatTen      while(LEN[I]&GT;ML)or((LEN[I]=ML) and(WID[I]&LT;MW)) DoInc (i); One      while(LEN[J]&LT;ML)or((LEN[J]=ML) and(WID[J]&GT;MW)) DoDec (j); A     ifI<=j Then begin -k:=len[i];len[i]:=len[j];len[j]:=K; -k:=wid[i];wid[i]:=wid[j];wid[j]:=K; the Inc (I);d EC (j); -                  End; -    untilI>J; -    ifI<w ThenKP (i,w); +    ifJ>t ThenKP (t,j); -   End; +  functionDelhead (I,j,k:longint): boolean; A   begin at     iff[j]-f[k]>-wid[i]* (len[j+1]-len[k+1]) ThenExit (True)Elseexit (false); -   End; -  functionDeltail (I,j,k:longint): boolean; -   begin -     if(F[i]-f[j]) * (len[j+1]-len[k+1]) > (f[j]-f[k]) * (len[i+1]-len[j+1]) Thenexit (True) -                                                                        Elseexit (false); in   End; -  to Begin +Assign (Input,'input.in'); reset (input); - READLN (n); the    fori:=1  toN Do * readln (Len[i],wid[i]); $Kp1, n);Panax Notoginsenginsn:=0; bist:=0; -    fori:=1  toN Do the    begin +     ifWid[i]>bist Then begin Abist:=Wid[i]; the Inc (INSN); +len[insn]:=Len[i]; -wid[insn]:=Wid[i]; $                         End; $    End; -n:=INSN; -head:=0; tail:=0; the    fori:=1  toN Do -    beginWuyi       while(Tail>head) and(Delhead (i,que[head],que[head+1])) DoInc (head); thej:=Que[head]; -f[i]:=f[j]+wid[i]*len[j+1]; Wu       while(Tail>head) and(Deltail (i,que[tail],que[tail-1])) DoDec (tail); - Inc (tail); Aboutque[tail]:=i; $    End; - Writeln (F[n]); - close (input); - End. A  +  

Bzoj 1597: [Usaco2008 Mar] Land purchase 2011-12-27

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.