Freelancer's Dreams

我们把每个二元组看成是平面上的一个点, 那么两个点的线性组合是两点之间的连线, 即x * (a1, b1) + y * (a1, b1) && x + y == 1,

那么n个点的线性组合就是一个凸包, 那么我们求出凸包和(0, 0)到(p, q)直线的交的那个较大值就是最优的组合平均速度。

需要注意的是, 直线和凸包可能没有交点, 需要加入(maxa, 0), (0, maxb)这两个点。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int dcmp(double x) {
if(fabs(x) < eps) return ;
else return x < ? - : ;
} struct Point {
double x, y;
Point(double x = , double y = ) : x(x), y(y) {}
}; double dist(const Point& a, const Point& b) {
return sqrt((a.x-b.x) * (a.x-b.x) + (a.y-b.y) * (a.y-b.y));
} typedef Point Vector; Point operator + (Vector A, Vector B) {return Point(A.x + B.x, A.y + B.y);}
Point operator - (Vector A, Vector B) {return Point(A.x - B.x, A.y - B.y);}
Point operator * (Vector A, double p) {return Point(A.x * p, A.y * p);}
Point operator / (Vector A, double p) {return Point(A.x / p, A.y / p);}
bool operator < (const Vector &A, const Vector &B) {return A.x < B.x || (A.x == B.x && A.y < B.y);}
bool operator == (const Vector &A, const Point &B) {return dcmp(A.x - B.x) == && dcmp(A.y - B.y) == ;}
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);} bool IsPointOnSegment(const Point &p, const Point &a1, const Point &a2) {
if(dcmp(Cross(a1-p,a2-p))) return ;
else if(dcmp(p.x-min(a1.x,a2.x)) >= && dcmp(p.x-max(a1.x,a2.x)) <=
&& dcmp(p.y-min(a1.y,a2.y)) >= && dcmp(p.y-max(a1.y,a2.y)) <= ) return ;
else return ;
} 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;
} int ConvexHull(vector<Point>& p, vector<Point>& ch) {
int n = p.size(), m = ;
sort(p.begin(), p.end());
for(int i = ; i < n; i++) {
while(m > && dcmp(Cross(ch[m-]-ch[m-], p[i]-ch[m-])) <= ) ch.pop_back(), m--;
ch.push_back(p[i]); m++;
}
int k = m;
for(int i = n - ; i >= ; i--) {
while(m > k && dcmp(Cross(ch[m-]-ch[m-], p[i]-ch[m-])) <= ) ch.pop_back(), m--;
ch.push_back(p[i]); m++;
}
return m;
} int n, p, q;
vector<Point> pt, ch; int main() {
scanf("%d%d%d", &n, &p, &q);
int mxa = -inf, mxb = -inf;
for(int i = ; i <= n; i++) {
int a, b; scanf("%d%d", &a, &b);
mxa = max(mxa, a);
mxb = max(mxb, b);
pt.push_back(Point(a, b));
}
pt.push_back(Point(mxa, ));
pt.push_back(Point(, mxb));
int m = ConvexHull(pt, ch);
Point v = Point(p, q);
Point ans = Point(-, -);
for(int i = ; i < m - ; i++) {
if(dcmp(Cross(ch[i], v)) * dcmp(Cross(v, ch[i + ])) >= ) {
if(Cross(v, ch[i + ] - ch[i]) == ) continue;
Point pp = GetLineIntersection(Point(, ), v, ch[i], ch[i + ] - ch[i]);
if(pp.x > ans.x) ans = pp;
}
}
printf("%.12f\n", v.x / ans.x);
return ;
} /*
*/

Codeforces 605C Freelancer's Dreams 凸包 (看题解)的更多相关文章

  1. Codeforces 229E Gifts 概率dp (看题解)

    Gifts 感觉题解写的就是坨不知道什么东西.. 看得这个题解. #include<bits/stdc++.h> #define LL long long #define LD long ...

  2. Codeforces 1155F Delivery Oligopoly dp(看题解)

    看别人写的才学会的... 我们考虑刚开始的一个点, 然后我们枚举接上去的一条一条链, dp[mask]表示当前已经加进去点的状态是mask所需的最少边数. 反正就是很麻烦的一道题, 让我自己写我是写不 ...

  3. [CodeForces-606E] Freelancer's Dreams 凸包 模型转换

    大致题意: 有一个人想要获得p个经验点和q元钱.现在给出n份工作,每份工作每天能得到Ai的经验值和Bi的钱,问最少需要工作多少天, 能使得总经验值>=p,总钱>=q. 先对给出的n份工作以 ...

  4. Codeforces 380D Sereja and Cinema (看题解)

    Sereja and Cinema 首先我们可以发现除了第一个人, 其他人都会坐在已入坐人的旁边. 难点在于计算方案数.. 我们可以从外往里把确定的人用组合数算上去,然后缩小范围. #include& ...

  5. Codeforces 442D Adam and Tree dp (看题解)

    Adam and Tree 感觉非常巧妙的一题.. 如果对于一个已经建立完成的树, 那么我们可以用dp[ i ]表示染完 i 这棵子树, 并给从fa[ i ] -> i的条边也染色的最少颜色数. ...

  6. Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)

    Coprime Arrays 啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊. #include<bits/stdc++.h> #define LL long long ...

  7. Codeforces 1101F Trucks and Cities dp (看题解)

    Trucks and Cities 一个很显然的做法就是二分然后对于每个车贪心取check, 这肯定会TLE, 感觉会给人一种贪心去写的误导... 感觉有这个误导之后很难往dp那个方向靠.. dp[ ...

  8. Codeforces 596D Wilbur and Trees dp (看题解)

    一直在考虑, 每一段的贡献, 没想到这个东西能直接dp..因为所有的h都是一样的. #include<bits/stdc++.h> #define LL long long #define ...

  9. Codeforces 965E Short Code 启发式合并 (看题解)

    Short Code 我的想法是建出字典树, 然后让后面节点最多的点优先向上移到不能移为止, 然后gg. 正确做法是对于当前的节点如果没有被占, 那么从它的子树中选出一个深度最大的点换到当前位置. 用 ...

随机推荐

  1. u-boot移植(十二)---代码修改---支持DM9000网卡

    一.准备工作 1.1 原理图 CONFIG_DM9000_BASE 片选信号是接在nGCS4引脚,若要确定网卡的基地址,则要根据片选信号的接口去确定. 在三星2440的DATASHEET中memory ...

  2. [C++]指针与引用(应用辨析)

    1.指针变量允许将一个整数经强制转换后赋值给指针变量    Eg:      float *fp;      fp = (float *)5000;//意义:将5000作为一个地址赋给指针变量fp 2 ...

  3. postman变量的使用和设置

    之前只是使用postman做接口管理——将各个项目使用到的接口分类管理起来,用的时候手动改参数调用.这次项目连着跑三个接口,需要用到前一个接口的参数,还来回切平台,真的很麻烦,所以就搜了一下有什么便利 ...

  4. L - The Shortest Path Gym - 101498L (dfs式spfa判断负环)

    题目链接:https://cn.vjudge.net/contest/283066#problem/L 题目大意:T组测试样例,n个点,m条边,每一条边的信息是起点,终点,边权.问你是不是存在负环,如 ...

  5. 《C#数据结构和算法》-排序

    7.7 各种排序方法的比较与讨论 排序在计算机程序设计中非常重要,上面介绍的各种排序方法各有优缺点, 适用的场合也各不相同.在选择排序方法时应考虑的因素有: ( )待排序记录的数目 n 的大小: ( ...

  6. Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法

    Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法 在使用Python的sklearn库时,发现sk ...

  7. 给bootstrap table设置行列单元格样式

    1.根据单元格或者行内其他单元格的内容,给该单元格设置一定的css样式 columns: [{ field: 'index', title: '序号', align:"center" ...

  8. CentOS挂载光盘

    mkdir /mnt/cdrom mount /dev/cdrom /mnt/cdrom umount /dev/cdrom /mnt/cdrom 在Ambari集群中配置192.168.0.210: ...

  9. 每天一个linux命令【转】

    转自:http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html 开始详细系统的学习linux常用命令,坚持每天一个命令,所以这个系列为每 ...

  10. SharePoint 2010 使用Install-SPSolution部署wsp包状态一直是”正在部署”

    1.服务器场信息如下: 2.使用下面命令部署,状态一直是"正在部署" Install-SPSolution –Identity xxxx.wsp –WebApplication h ...