【链接】
【题意】游泳+跑步比赛。 先游泳,然后跑步. 最先到终点的人是winner. 但是现在游泳的距离和跑步的距离长度都不确定。 S和R. 给你n个人,告诉你每个人游泳的速度以及它们跑步的速度。 现在问你在改变S,R的情况下,第i个人有没有可能为winner. 输出所有可能为winner的人的编号。
【题解】
每个人所花费的时间为\(\frac{S}{si} + \frac{R}{ri}\) 可以看成是向量{S,R}和(\(\frac{1}{si}\),\(\frac{1}{ri}\))的点积。 考虑点积的几何意义为向量上的投影长度。 而一堆点里面,和某个固定的向量的投影长度.↓↓ 会发现,总是凸包的边界上的某个点。 接下来的思路来自这里 看完思路之后接着 则,只要求出凸包。 然后找最坐标的x值最小的点就好(有多个x相同就找y尽量小的); ->求完凸包之后,因为排了个序,ch[0]就是这个最左的点。 然后找一个y值为最小的点就好了。 (多个最小,直接取x最小的就好); 所以求完凸包之后,顺序枚举,找到一个y=y的最小值,那么这一段就是所需的了。 重复点不要忘记加上去~就是那个to.
【代码】
#includeusing namespace std;struct Point { double x, y; int id; Point() {} Point(double x, double y) { this->x = x; this->y = y; } void read(int id) { int s, b; scanf("%d%d", &s, &b); x = 1000000.0 / s; y = 1000000.0 / b; this->id = id; }};const double eps = 1e-16;int dcmp(double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}typedef Point Vector;Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y);}Vector operator - (Vector A, Vector B) { return Vector(A.x - B.x, A.y - B.y);}Vector operator * (Vector A, double p) { return Vector(A.x * p, A.y * p);}Vector operator / (Vector A, double p) { return Vector(A.x / p, A.y / p);}bool operator < (const Point& a, const Point& b) { return a.x < b.x || (dcmp(a.x - b.x) == 0 && a.y < b.y);}bool operator == (const Point& a, const Point& b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;}double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //点积double Length(Vector A) {return sqrt(Dot(A, A));} //向量的模double Angle(Vector A, Vector B) {return acos(Dot(A, B) / Length(A) / Length(B));} //向量夹角double Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //叉积double Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);} //有向面积struct Line { Point v, p; Line() {} Line(Point v, Point p) { this->v = v; this->p = p; } Point point(double t) { return v + p * t; }};//向量旋转Vector Rotate(Vector A, double rad) { return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));}Vector AngleBisector(Point p, Vector v1, Vector v2){//给定两个向量,求角平分线 double rad = Angle(v1, v2); return Rotate(v1, dcmp(Cross(v1, v2)) * 0.5 * rad);}//判断3点共线bool LineCoincide(Point p1, Point p2, Point p3) { return dcmp(Cross(p2 - p1, p3 - p1)) == 0;}//判断向量平行bool LineParallel(Vector v, Vector w) { return Cross(v, w) == 0;}//判断向量垂直bool LineVertical(Vector v, Vector w) { return Dot(v, w) == 0;}//计算两直线交点,平行,重合要先判断Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) { Vector u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v * t;}//点到直线距离double DistanceToLine(Point P, Point A, Point B) { Vector v1 = B - A, v2 = P - A; return fabs(Cross(v1, v2)) / Length(v1);}//点到线段距离double DistanceToSegment(Point P, Point A, Point B) { if (A == B) return Length(P - A); Vector v1 = B - A, v2 = P - A, v3 = P - B; if (dcmp(Dot(v1, v2)) < 0) return Length(v2); else if (dcmp(Dot(v1, v3)) > 0) return Length(v3); else return fabs(Cross(v1, v2)) / Length(v1);}//点在直线上的投影点Point GetLineProjection(Point P, Point A, Point B) { Vector v = B - A; return A + v * (Dot(v, P - A) / Dot(v, v));}//线段相交判定(规范相交)bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) { double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1); return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;}//可以不规范相交bool SegmentProperIntersection2(Point a1, Point a2, Point b1, Point b2) { double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1); return max(a1.x, a2.x) >= min(b1.x, b2.x) && max(b1.x, b2.x) >= min(a1.x, a2.x) && max(a1.y, a2.y) >= min(b1.y, b2.y) && max(b1.y, b2.y) >= min(a1.y, a2.y) && dcmp(c1) * dcmp(c2) <= 0 && dcmp(c3) * dcmp(c4) <= 0; }//判断点在线段上, 不包含端点bool OnSegment(Point p, Point a1, Point a2) { return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;}//n边形的面积double PolygonArea(Point *p, int n) { double area = 0; for (int i = 1; i < n - 1; i++) area += Cross(p[i] - p[0], p[i + 1] - p[0]); return area / 2;}//点是否在多边形内部int isPointInPolygon(Point o, Point *p, int n) { int wn = 0; for (int i = 0; i < n; i++) { if (OnSegment(o, p[i], p[(i + 1) % n])) return -1; int k = dcmp(Cross(p[(i + 1) % n] - p[i], o - p[i])); int d1 = dcmp(p[i].y - o.y); int d2 = dcmp(p[(i + 1) % n].y - o.y); if (k > 0 && d1 <= 0 && d2 > 0) wn++; if (k < 0 && d2 <= 0 && d1 > 0) wn--; } if (wn != 0) return 1; return 0;}const int N = 200005;int to[N];//凸包int ConvexHull(Point *p, int n, Point *ch) { sort(p, p + n); int m = 0; memset(to, -1, sizeof(to)); //两个叉积改成<,可以求共线凸包 for (int i = 0; i < n; i++) { to[i] = i; if (i && p[i] == p[i - 1]) { to[i] = to[i - 1]; continue; } while (m > 1 && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0) m--; ch[m++] = p[i]; } int k = m; for (int i = n - 2; i >= 0; i--) { while (m > k && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0) m--; ch[m++] = p[i]; } if (n > 1) m--; return m;}Point a[N+10],ch[N+10];bool vis[N+10];int n,m;double mi = 1e18;int main(){ #ifdef LOCAL_DEFINE freopen("F:\\c++source\\rush_in.txt","r",stdin); #endif scanf("%d",&n); for (int i = 0;i < n;i++){ a[i].read(i); } m = ConvexHull(a,n,ch); for (int i = 0;i < m;i++) mi = min(mi,ch[i].y); for (int i = 0;i < m;i++){ vis[ch[i].id] = 1; if (ch[i].y==mi) break; } for (int i = 0;i < n;i++) if (vis[a[to[i]].id]) vis[a[i].id] = 1; for (int i = 0;i < n;i++) if (vis[i]){ printf("%d",i+1); if (i==n-1) puts("");else putchar(' '); } return 0;}