Topic Description
Transfer Door solving
A car ride is v*t+k.
As a straight line is the horizontal visible line that problem ...
The slope is sorted by the monotonic stack, each time the intersection is counted and then judged if it's covered.
The >=0 of the horizontal axis of the final stack and the next line of intersection is legal.
Pit point:
To judge the parallel straight line, choose b the largest
To determine the coincidence line, the stack can only keep one, the last output when all the output
(cannot be marked directly at the time of maintenance because it may be ejected later)
The problem is very clear, as long as there is no more than it on the line, so the point of coincidence is also satisfied
You can also use Nlogn to make it seem like code
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <
Cmath> using namespace std;
#define N 10005 const double eps=1e-12;
int dcmp (double x) {if (x<=eps&&x>=-eps) return 0;
Return (x>0) 1:-1;
} struct line {int id,num;
Double k,b; BOOL operator < (const line &a) const {return k<a.k| |
a.k==k&&b>a.b;
}
};
int n,top,ans[n];
Line L[n],stack[n];
BOOL Flag[n]; Double X (line P,line q) {return (Q.B-P.B)/(P.K-Q.K);} double Y (line l,double X) {return x*l.k+l.b;} bool Check
(line P,line Q,line R)
{Double x=x (p,q);
Double py=y (p,x);
Double ry=y (r,x);
Return dcmp (Py-ry) <0;
int main () {scanf ("%d", &n);
for (int i=1;i<=n;++i) scanf ("%lf", &l[i].b), l[i].id=i;
for (int i=1;i<=n;++i) scanf ("%lf", &L[I].K);
Sort (l+1,l+n+1);
for (int i=1;i<=n;++i) l[i].num=i;
for (int i=1;i<=n;++i) { if (top&&dcmp (L[I].K-STACK[TOP].K) ==0) continue;
while (Top>1&&check (Stack[top],stack[top-1],l[i]))--top;
Stack[++top]=l[i];
for (int i=1;i<=top;++i) {if (i!=top) {double x=x (stack[i],stack[i+1]);
if (dcmp (x) <0) continue;
} line Now=stack[i];
for (int i=now.num;i<=n;++i) if (dcmp (NOW.K-L[I].K) ==0&&dcmp (now.b-l[i].b) ==0) flag[l[i].id]=1;
else break;
for (int i=1;i<=n;++i) if (flag[i]) ++ans[++ans[0]]=i;
printf ("%d\n", Ans[0]);
for (int i=1;i<=ans[0];++i) printf ("%d%c", ans[i], "\ n" [i==ans[0]]); }