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. HDU 2522 A simple problem (模拟)

    题目链接 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第 ...

  2. ROS 时间同步问题

    0. 问题 两台ubuntu主机无法与一台debian主机使用分布式通信,摄像头发出的话题机器人收不到,考虑是时间同步的问题. 也可能是系统不统一的问题; 今天在家实验了一下,时间差6min,照样可以 ...

  3. SpringBoot整合MyBatis(注解版)

    详情可以参考Mybatis官方文档 http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/ (1). ...

  4. SpringMVC使用Redis作为缓存提供者

    (1)pom添加依赖项 <dependency> <groupId>org.springframework.data</groupId> <artifactI ...

  5. ARMV8 datasheet学习笔记4:AArch64系统级体系结构之Self-hosted debug

    1. 前言 2. 关于self-hosted debug Debugger调试器 是操作系统或系统软件的一部分,它会处理debug exception或修改debug system register, ...

  6. Libevent源码分析—从使用Libevent库开始

    练习libevent库的使用,主要是几个API的调用顺序.根据event.h的开头注释部分可知,要使用libevent库,主要的几个API及调用顺序为:         event_base()初始化 ...

  7. springboot系列三、springboot 单元测试、配置访问路径、多个配置文件和多环境配置,项目打包发布

    一.单元测试 生成的demo里面包含spring-boot-starter-test :测试模块,包括JUnit.Hamcrest.Mockito,没有的手动加上. <dependency> ...

  8. 【转】CString与string、char*的区别和转换

    我们在C++的开发中经常会碰到string.char*以及CString,这三种都表示字符串类型,有很多相似又不同的地方,常常让人混淆.下面详细介绍这三者的区别.联系和转换: 各自的区别 char*: ...

  9. go语言标准库 时刻更新

    Packages   Standard library Other packages Sub-repositories Community Standard library ▾ Name Synops ...

  10. android 获取手机GSM/CDMA信号信息,并获得基站信息

    本文转自:http://software.intel.com/zh-cn/blogs/2011/12/16/android-gsmcdma/ 在Android中我们常用的轻松获取WIFI信号列表,那如 ...