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. VMware WorkStation9.0 安装centos-6.4

    1,设置虚拟机内存为8G时,启动报内存不足错误: Not enough physical memory is available to power on this virtual machine 解决 ...

  2. 19. SpringBoot_web开发-使用外部Servlet容器&JSP支持

    還沒有web.xml,生  配置tomcat 嵌入式Servlet容器:应用打成可执行的jar 优点:简单.便携: 缺点:默认不支持JSP.优化定制比较复杂 使用定制器[ServerPropertie ...

  3. TCP/IP详解 卷1 第十八章 TCP的建立与终止

    第十八章 TCP的建立与终止 tcpdump Tcpdump可以将网络中传送的数据报完截获下来进行分析.它支持针对网络层.协议.主机.网络或端口的过滤,并提供and.or.not等逻辑语句来帮助你去掉 ...

  4. 如何学好web安全

    web服务组件: 横向就是如图所示,纵向就是数据流:数据流说白了就是http协议. 举例: 1.如果在操作系统没有处理好,就产生了OS命令执行的安全问题: 2.如果在存储层的数据库中没有处理好,数据库 ...

  5. 解决NO migrations to apply

    创建表之后,遇到models模型变动,故当时做了删除应用文件夹下migrations文件,删除后重建,但重建后执行模型合并操作结果为No Changes,无法创建数据表 执行python3 manag ...

  6. SpringMVC跨重定向请求传递数据

    (1)使用URL模板以路径变量和查询参数的形式传递数据(一些简单的数据) @GetMapping("/home/index") public String index(Model ...

  7. Dubbo监控中心

    (1).dubbo-admin(管理控制台) 1).从https://github.com/apache/incubator-dubbo-ops下载解压 2).修改dubbo-admin配置文件中zo ...

  8. f-GAN

    学习总结于国立台湾大学 :李宏毅老师 f-GAN: Training Generative Neural Samplers using Variational Divergence Minimizat ...

  9. Django中全局Context处理器

    1.模板标签和模板变量 模板标签在{% %}中定义: {% if is_logged_in %} Thanks for logging in! {% else %} Please log in. {% ...

  10. 026_关于shell中的特殊变量$0 $n $* $@ $! $?

    一. $n:获取当前执行的shell脚本的第N个参数,n=1..9,当n为0时表示脚本的文件名,如果n大于9,用大括号括起来like${10}. $*:获取当前shell的所有参数,将所有的命令行参数 ...