BZOJ3822: Literature

Source: Internet
Author: User

Descriptionthe big sauce and the chairman are a pair of good friends. They are very fond of reading books, often read the relevant fields of the book, the systematic study. One day the chairman listed a list, which contains a total of P-books, including "Christophe", "celebrity biography" and other masterpieces. As a well-known young man with a high degree of literature, the giant sauce intends to use as little time as possible to read all the books in this list. as a cultural man, the way to read books is also different from the average person. He uses a way of reading called "Bulk reading". First, according to his preference, he gave a parameter x, y for each book, where the two parameters of I book are xi,yi. Of course, due to the unique taste of the sauce, there may be two different books, their x and Y parameters are the same. And every time he reads, he sets three coefficients a, B, C, all the books that meet ax+by≤c can be read through this "bulk reading", which takes a total of w time in bulk reading. now, the giant sauce has n "bulk reading" scheme, the first type of "bulk reading" three parameters for Ai,bi,ci, the time required for WI. Now the big sauce is going to select a number of these n "bulk readings" so that the giant sauce can read all the books in as little time as possible. Now we want to know, how much time does the sauce take at least? InputThe first line of two positive integer n,p, respectively, represents the number of scenarios for "bulk reading" and the number of books. The next n lines, four integers per line, where line I contains four integer ai,bi,ci,wi, represents the "bulk reading" scenario for the I type. next P line, two integers per line, where line I contains two integer xi,yi, representing the parameters of Book I. OutputAn integer line that represents the minimum time required. If you cannot read all the books anyway, the output −1.

Each book is viewed as a flat point, and each scheme is a half-plane, which translates into a half-plane with minimum weights and covers all points.

The first can be a half plane covering all points of the case, the rest of the solution has at least two half-plane, then you can enumerate the two half-plane, with the half-plane intersection as the center of the remaining non-covered points for the polar order

It can be found that there is a way to divide the contribution, so that the sorted point is divided into several successive segments, each segment is solved by a half plane coverage, so can be interval DP, the total complexity is O (N4)

When the decision point is in the half plane, the calculated result is within 1012, and the calculated result and the original value are all integers, and the double can be used to accurately represent and calculate

#include <cstdio>#include<cmath>#include<cstring>#include<algorithm>Const intinf=0x3f3f3f3f;intn,m;structhp{DoubleA,b,c;intv; voidRead () {scanf ("%lf%lf%lf%d",&a,&b,&c,&v);}} h[103];structpos{Doublex, y; voidRead () {scanf ("%LF%LF",&x,&y);} BOOL inch(HP W) {returnx*w.a+y*w.b<=w.c;} POSoperator-(pos W) {return(POS) {x-w.x,y-w.y};} Double operator* (pos W) {returnx*w.y-y*w.x;}} p[103],s[103];p os p0;BOOL operator<(pos A,pos b) {return(a-p0) * (B-P0) <0;} POS Cross (HP x,hp y) {Doublev=x.a*y.b-y.a*x.b; return(POS) {(x.c*y.b-y.c*x.b)/V, (X.C*Y.A-Y.C*X.A)/-v};}intf[103],g[103][103],sp=0, ans=inf;voidminsint&a,intb) {if(a>b) a=b;}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;++i) h[i].read ();  for(intI=1; i<=m;++i) p[i].read ();  for(intI=1; i<=n;++i) {         for(intj=1; j<=m;++j)if(!p[j].inch(H[i]))Gotoo;    mins (ANS,H[I].V); O:; }     for(intI=1; i<=n;++i) {         for(intj=1; j<i;++j) {SP=0; P0=Cross (H[i],h[j]);  for(intk=1; k<=m;++k)if(! (P[k].inch(H[i]) | | P[K].inch(H[j]))) s[++sp]=P[k]; Std::sort (S+1, s+sp+1); Memset (F,0x3f,sizeoff); Memset (g,0x3f,sizeofg);  for(intA=1; a<=n;++a)if(a!=i&&a!=j) {                 for(intL=1, r;l<=sp;++l) {                    if(!s[l].inch(H[a]))Continue;  for(r=l;r<sp&&s[r+1].inch(H[a]); + +S);                    mins (G[L][R],H[A].V); L=r+1; }            }             for(intD=sp;d>1;--d) for(intL=1, r=d;r<=sp;++l,++r) mins (g[l][r-1],g[l][r]), mins (g[l+1][r],g[l][r]); f[0]=0;  for(intb=1; b<=sp;++b) for(intA=0; a<b;++a) mins (f[b],f[a]+g[a+1][b]); mins (ANS,F[SP]+h[i].v+h[j].v); }} printf ("%d", ans==inf?-1: ans); return 0;}

BZOJ3822: Literature

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.