Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1071
The topic is very good, incredibly wrote for a long time, the problem finding really much;
There are two main ways of doing this:
O (N^2LGN), through priority heap maintenance, first equation transformation:a*height+b*speed-c<=a*minheight+b*minspeed;
Add A[i].val=a*height+b*speed-c:
Sort a by height;
Then enumerate I take a[i].s as min
1 /* ***********************************************2 author:forgot933 Created time:2014/12/23 Tuesday morning 9:00:414 File Name:5 ************************************************ */6 7#include <stdio.h>8#include <string.h>9#include <iostream>Ten#include <algorithm> One#include <vector> A#include <queue> -#include <Set> -#include <map> the#include <string> -#include <stdlib.h> -#include <time.h> - using namespacestd; + - #defineN 5555 +typedefLong Longll; APriority_queue<ll>Q; at - structnode - { - ll H,s; - ll Val; - BOOL operator< (ConstNode &b)Const{ in returnH>b.h; - } to }a[n]; + - the intMain () * { $ intN;Panax Notoginseng ll A,b,c; -Cin>>n>>a>>b>>C; the for(intI=1; i<=n;i++){ +Cin>>a[i].h>>A[i].s; Aa[i].val=a*a[i].h+b*a[i].s-C; the } +ll ans=1; -Sort (A +1, a+n+1); $ $ for(intI=1; i<=n;i++) - { -ll minh=a[i].h; thell mins=A[i].s; - while(!q.empty ()) Q.pop ();Wuyi Q.push (a[i].val); the for(intj=1; j<=n;j++) - if(j!=i&&a[j].s>=mins) Wu { -Minh=min (minh,a[j].h); Aboutll tmp=b*mins+a*Minh; $ if(a[i].val>tmp) Break; - while(!q.empty () &&q.top () >tmp) Q.pop (); - if(a[j].val<=tmp) - { A Q.push (a[j].val); +ans=Max (ans, (LL) q.size ()); the } - } $ } thecout<<ans<<Endl; the return 0; the}
View Code
Speed
then temporarily minheight=a[i].h;
A[i].h are sorted from large to small;
Next Maintenance heap, we enumerate J for J!=i and A[j].s>=mins,
Update MinHeight at the same time;
Then the Val satisfies the pressure into the heap;
To Q.top () >val q.pop ();
Because the mins is fixed, the Minh is monotonically decreasing, so the back of the front is satisfied (please consider it carefully);
Time is 1100ms;
The second type is O (n*n);
Time is 848ms;
Keywords: monotonous;
1 /* ***********************************************2 author:forgot933 Created time:2014/12/23ðçæú¶þïâîç2:46:364 File name:c.cpp5 ************************************************ */6 7#include <stdio.h>8#include <string.h>9#include <iostream>Ten#include <algorithm> One#include <vector> A#include <queue> -#include <Set> -#include <map> the#include <string> -#include <math.h> -#include <stdlib.h> -#include <time.h> + using namespacestd; - +typedefLong Longll; A #defineN 5555 at structnode - { - inth,v; - ll Val; - }h[n],v[n],a[n],r[n]; - in intcmp1 (node X,node y) - { to if(X.h==y.h)returnx.v<y.v; + returnx.h<Y.h; - } the intcmp2 (node X,node y) * { $ if(X.V==Y.V)returnx.h<Y.h;Panax Notoginseng returnx.v<y.v; - } the + intCmp3 (node X,node y) A { the returnx.val<Y.val; + } - $ $ intMain () - { - intN; the ll A,b,c; -Cin>>n>>a>>b>>C;Wuyi for(intI=0; i<n;i++){ theCin>>a[i].h>>a[i].v; -a[i].val=a*a[i].h+b*a[i].v-C; Wuh[i]=v[i]=A[i]; - } AboutSort (a,a+N,cmp3); $Sort (v,v+n,cmp2); -Sort (h,h+n,cmp1); - intans=0; - for(intI=0; i<n;i++) A { + intminh=h[i].h,p=0, cnt=0, tot=0; the for(intj=0; j<n;j++) - if(v[j].h>=minh&&v[j].v<=h[i].v) $r[tot++]=V[j]; the for(intj=0; j<tot;j++) the { the intminv=r[j].v; thell res=a*minh+b*MINV; - while(p<n&&a[p].val<=Res) in { the if(a[p].h<minh| | A[P].V<MINV) cnt++; thep++; About } theAns=max (P-Cnt,ans); the if(res>=a*r[j].h+b*r[j].v-c) cnt++; the if(p==n) Break; + } - } theprintf"%d\n", ans);Bayi return 0; the}
View Code
First sort by some keywords.
For I minh=a[i].h;
Then enumerate J to find mins,mins<a[i],s;
then the monotone queue;
There is such a property: when we enumerate pointers in the order of Val from small to large, we enumerate the mins is small to large, so:
(here) The elements of the front must satisfy the back, how to understand?
The mins2 of the enumeration satisfies all elements of the mins1, so the pointer p does not have to be 0.
So it will O (n^2);
Bzoj 1071 Team