HDU 4791 Alice's Print Service (2013 Changsha Regional game a question)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4791

Problem Solving report: Print shop to provide paper sheet service, charge fee, input format is s1 p1 s2 p2 s3 p3 ... Indicates that the unit price of S1 to S2 sheet is P1, and the unit price of S2 to S3 is P2 in the print interval .... Finally, the unit price of SN to infinity is pn, so you ask for the minimum total cost of printing K-sheet paper. There are M queries.

Because S1*P1 > s2 * p2 > S3*p3 ..., it is clear that the zone in which K is added is the X-band, then the minimum cost is either K * px, or more printing, you can make sure that the number of prints will be the number of left end points of an interval after the X interval. , because it has exceeded the number of sheets I want to print, so the number of the middle of any interval must be greater than the number of the left end of the interval, so now I have to decide how many to print, it is clear that the number of prints is either the K I am typing now, or the value of the left end of an interval 5, so I can sweep it back and forth, and I can determine which interval is the lowest cost of the interval. Then it's OK to use two points to find out which interval K belongs to.

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5 6 using namespacestd;7 #defineLL __int64//I 'll remember to change it later .8 #defineMAXN 1000109 structnodeTen { One LL tot,p; A LL s1,s2; -     intNext; - }ALL[MAXN]; the intFIND_S1 (LL d,node* temp,intLintR) - { -      while(L <R) -     { +         intMid = (L + r)/2; -         if(d <= temp[mid].s1) R =mid; +         Else if(d > temp[mid].s1) L = mid +1; A     } at     if(! (d >= temp[l].s1 && D < temp[l].s2))returnL-1; -     returnl; - } - ll Min (ll A,ll b) - { -     returnA <= b?a:b; in } - ll Max (ll A,ll b) to { +     returnA >= b?a:b; - } the intMain () * { $ //freopen ("in", "R", stdin);Panax Notoginseng     intt,n,m; -scanf"%d",&T); theLL d,s =0, T1,t2; +      while(t--) A     { thescanf"%d%d",&n,&m); +scanf"%i64d",&s); -          for(inti =0; i < n-1;++i) $         { $scanf"%i64d%i64d",&all[i].p,&all[i].s2); -ALL[I].S1 =s; -All[i].tot = All[i].s1 *ALL[I].P; thes =all[i].s2; -         }Wuyiall[n-1].S1 =s; theall[n-1].S2 =0x7fffffff; -scanf"%i64d", &all[n-1].P); Wuall[n-1].tot = all[n-1].P * all[n-1].s1; -all[n-1].next =N; AboutAll[n] = all[n-1]; $         intPP =N; -          for(inti = n1; I >=0;--i) -         { -All[i].next =pp; A             if(All[pp].tot > All[i].tot) pp =i; +         } the          for(inti =0; I < m;++i) -         { $scanf"%i64d",&d); the             intQ = find_s1 (D,all,0, N-1); theT1 = ALL[Q].P *D; the             if(All[q].f! = N1)//First n-1 the             { -T2 = ALL[ALL[Q].NEXT].P *Max (all[all[q].next].s1,d); inprintf"%i64d\n", Min (T1,T2)); the             } the             Elseprintf"%i64d\n", T1);//situation in nth About         } the     } the     return 0; the}
View Code

HDU 4791 Alice's Print Service (2013 Changsha Regional game a question)

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.