Freelancer's Dreams
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Mikhail the Freelancer dreams of two things: to become a cool programmer and to buy a flat in Moscow. To become a cool programmer, he needs at least p experience points, and a desired flat in Moscow costs q dollars. Mikhail is determined to follow his dreams and registered at a freelance site.

He has suggestions to work on n distinct projects. Mikhail has already evaluated that the participation in the i-th project will increase his experience by ai per day and bring bi dollars per day. As freelance work implies flexible working hours, Mikhail is free to stop working on one project at any time and start working on another project. Doing so, he receives the respective share of experience and money. Mikhail is only trying to become a cool programmer, so he is able to work only on one project at any moment of time.

Find the real value, equal to the minimum number of days Mikhail needs to make his dream come true.

For example, suppose Mikhail is suggested to work on three projects and a1 = 6, b1 = 2, a2 = 1, b2 = 3, a3 = 2, b3 = 6. Also, p = 20and q = 20. In order to achieve his aims Mikhail has to work for 2.5 days on both first and third projects. Indeed,a1·2.5 + a2·0 + a3·2.5 = 6·2.5 + 1·0 + 2·2.5 = 20 and b1·2.5 + b2·0 + b3·2.5 = 2·2.5 + 3·0 + 6·2.5 = 20.

Input

The first line of the input contains three integers np and q (1 ≤ n ≤ 100 000, 1 ≤ p, q ≤ 1 000 000) — the number of projects and the required number of experience and money.

Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 1 000 000) — the daily increase in experience and daily income for working on the i-th project.

Output

Print a real value — the minimum number of days Mikhail needs to get the required amount of experience and money. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Sample test(s)
input
3 20 20
6 2
1 3
2 6
output
5.000000000000000
input
4 1 1
2 3
3 2
2 3
3 2
output
0.400000000000000
Note

First sample corresponds to the example in the problem statement.

题意:给出n个二元组(ai,bi),给出(p,q),要求min(∑xi (1 <= i <= n) ),使得 ∑xi*ai >= p, 且∑xi*bi >= q。问min值是多少。

分析:考虑向量(ai,bi)

将其考虑为平面上的一个点。

观察一下它的凸包,显然凸包里面的所有点都可以是组成凸包的点的线性组合(在小于等于单位长度内)。

我们现在要做的是找一个最小的放大倍数x使得这个凸包包含(p,q)

如果是包含的话有点难搞,如果是恰好等于(恰好在边界上)的话就好搞了。

我们假设我们可以选择某些二元组只有一边有影响,即我们只取他的ai或者bi,这样的话,就相当于求恰好等于时的答案了。(因为如果是包含的话,一定可以使某些点的某一边没有影响,进而变为恰好等于)。

这时显然相当于加入两个二元组(max ai, 0)、(0, max bi),在求一次凸包。

求使(p, q)恰好在边界上的最小倍数。

求这个倍数的话。

从S(0,0)到G(p,q)拉一条线,设SG这条直线与凸包交与X点,那么倍数显然是SG/SX。

 /**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const DB EPS = 1e-, PI = acos(-1.0);
const int N = ;
class Point
{
private :
int x, y;
public :
Point() {}
Point(const int tx, const int ty)
{
x = tx, y = ty;
}
inline bool operator <(const Point &t) const
{
if(x != t.x) return x > t.x;
return y < t.y;
} inline bool operator ==(const Point &t) const
{
return x == t.x && y == t.y;
} inline void Read()
{
scanf("%d%d", &x, &y);
} inline int Get(const int t) const
{
return t ? y : x;
}
} arr[N];
int n, p, q;
DB ans; inline void Input()
{
scanf("%d%d%d", &n, &p, &q);
for(int i = ; i < n; i++) arr[i].Read();
} inline LL Multi(const Point &o, const Point &a, const Point &b)
{
LL d1[], d2[];
for(int i = ; i < ; i++)
d1[i] = a.Get(i) - o.Get(i), d2[i] = b.Get(i) - o.Get(i);
return d1[] * d2[] - d1[] * d2[];
} inline void GetHull(Point *arr, int &n)
{
static int index[N];
int len = ;
for(int i = ; i < n; i++)
{
while(len >= && Multi(arr[index[len - ]], arr[index[len - ]], arr[i]) <= ) len--;
index[len++] = i;
}
for(int i = ; i < len; i++) arr[i] = arr[index[i]];
n = len;
} inline bool Cross(const Point &a, const Point &b, const Point &c, const Point &d)
{
LL dir1 = Multi(a, b, c), dir2 = Multi(a, b, d);
if(!dir1 || !dir2) return ;
return (dir1 > ) ^ (dir2 > );
} inline DB Sqr(DB x)
{
return x * x;
} inline DB Dist(const Point &a, const Point &b)
{
DB ret = 0.0;
for(int i = ; i < ; i++)
ret += Sqr(a.Get(i) - b.Get(i));
return sqrt(ret);
} inline void Solve()
{
ans = 1.0 * INF;
for(int i = ; i < n; i++)
{
DB t = max((1.0 * p) / arr[i].Get(), (1.0 * q) / arr[i].Get());
ans = min(ans, t);
} int mx1 = , mx2 = ;
for(int i = ; i < n; i++)
mx1 = max(mx1, arr[i].Get()),
mx2 = max(mx2, arr[i].Get());
arr[n] = Point(mx1, ), arr[n + ] = Point(, mx2);
n += ;
sort(arr, arr + n);
n = unique(arr, arr + n) - arr; GetHull(arr, n); Point g = Point(p, q), s = Point(, );
for(int i = ; i < n - ; i ++)
{
if(!Cross(s, g, arr[i], arr[i + ])) continue;
Point b = arr[i], c = arr[i + ];
DB bc = Dist(b, c), gc = Dist(g, c),
sg = Dist(s, g), sb = Dist(s, b), sc = Dist(s, c);
/*DB scb = acos((Sqr(sc) + Sqr(bc) - Sqr(sb)) / (2.0 * sc * bc)), csg = acos((Sqr(sc) + Sqr(sg) - Sqr(gc)) / (2.0 * sc * sg));
DB sxc = PI - scb - csg;
DB sx = sin(scb) * (sc / sin(sxc));*/
DB cosscb = (Sqr(sc) + Sqr(bc) - Sqr(sb)) / (2.0 * sc * bc), coscsg = (Sqr(sc) + Sqr(sg) - Sqr(gc)) / (2.0 * sc * sg);
DB sinscb = sqrt( - Sqr(cosscb)), sincsg = sqrt( - Sqr(coscsg));
DB sinsxc = sinscb * coscsg + cosscb * sincsg;
DB sx = sinscb * (sc / sinsxc);
ans = min(ans, sg / sx);
} printf("%.15lf\n", ans);
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}

后记:

  CF上TOOSIMPLE大神提出:由于线性组合的对偶性,可以使用三分的手段做出这道题,非常简单。

  这是证明:

We want to minimize  given that  and , and .

Now, let's add a linear combination of the two constraints together. They will be weighted by 2 numbers. So, we have .

The left hand side can be rewritten as .

Note that if we add the constraints , then we'll have .

So, to get a good lower bound, we can solve the following problem:  given that  for all i. Solving this new linear program will give us the best lower bound we can get for our original problem.

贴上TooSimple大神的代码。

 #include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
typedef long double LD;
const int N=;
int n,p,q,a[N],b[N];
LD ff(LD x) {
LD mv=;
rep(i,,n) mv=min(mv,(-b[i]*x)/a[i]);
return mv*p+x*q;
}
int main() {
scanf("%d%d%d",&n,&p,&q);
rep(i,,n) scanf("%d%d",a+i,b+i);
LD l=,r=; r/=*max_element(b,b+n);
rep(i,,) {
LD fl=(l+l+r)/,fr=(r+r+l)/;
if (ff(fl)>ff(fr)) r=fr; else l=fl;
}
printf("%.10f\n",(double)ff((l+r)/));
}

CF#335 Freelancer's Dreams的更多相关文章

  1. Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何

    C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...

  2. Codeforces 605C Freelancer's Dreams 凸包 (看题解)

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

  3. Codeforces Round #335 (Div. 1)--C. Freelancer's Dreams 线性规划对偶问题+三分

    题意:p, q,都是整数. sigma(Ai * ki)>= p, sigma(Bi * ki) >= q; ans = sigma(ki).输出ans的最小值 约束条件2个,但是变量k有 ...

  4. CF#335 Intergalaxy Trips

     Intergalaxy Trips time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. CF#335 Board Game

    Board Game time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input ...

  6. CF#335 Lazy Student

    Lazy Student time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. CF#335 Sorting Railway Cars

    Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. codeforce 605BE. Freelancer's Dreams

    题意:给你n个工程,做了每个工程相应增长x经验和y钱.问你最少需要多少天到达制定目标.时间可以是浮点数. 思路:杜教思路,用对偶原理很简易.个人建议还是标准解题法,凸包+线性组合. #include& ...

  9. CF #335 div1 A. Sorting Railway Cars

    题目链接:http://codeforces.com/contest/605/problem/A 大意是对一个排列进行排序,每一次操作可以将一个数字从原来位置抽出放到开头或结尾,问最少需要操作多少次可 ...

随机推荐

  1. innodb之超时参数配置

    可参考:http://www.penglixun.com/tech/database/mysql_timeout.html 下面内容摘取自上面这个链接. connection_timeout,只是设置 ...

  2. java链式编程设计

    一般情况下,对一个类的实例和操作,是采用这种方法进行的: Channel channel = new Channel(); channel.queueDeclare(QUEUE_NAME, true, ...

  3. Android Service 与 IntentService

    Service 中的耗时操作必须 在 Thread中进行: IntentService 则直接在 onHandleIntent()方法中进行

  4. 八皇后(dfs+回溯)

    重看了一下刘汝佳的白板书,上次写八皇后时并不是很懂,再写一次: 方法1:逐行放置皇后,然后递归: 代码: #include <bits/stdc++.h> #define MAXN 8 # ...

  5. css控制文字显示长度,超过用省略号替代

    .line_text { width:200px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; } <span cl ...

  6. 在Eclipse中自定义类似syso的快捷代码模板

    sysout/syso syserr/ syse 点击菜单栏的“Window”->“Preferences”,打开“Preferences”对话框.在Preferences”对话框中点击“Jav ...

  7. Pyqt清空Win回收站

    Pyqt清空回收站其实的调用Python的第三方库,通过第三方库调用windows的api删除回收站的数据 一. 准备工作 先下载第三方库winshell 下载地址: https://github.c ...

  8. 【翻译二十】-java线程池

    Thread Pools Most of the executor implementations in java.util.concurrent use thread pools, which co ...

  9. mysql 如何设置自动增长序列 sequence(一)

    背景:由于项目需要,必须用mysql设置主键自增长,而且想用字符串的.经过上网查找并且实验,终于做出了一套方案.现在就共享给大家! 解决思路:由于mysql不带sequence,所以要手写的,创建一张 ...

  10. 自制工具:迅速打开一个Node 环境的Playground

    需求 经常有这种情况,写代码的时候需要实验种想法,亟需一种playground 环境来玩耍.如果是前端的话可以打开chrome 的控制台,但是如果是Node 的话就比较麻烦了.我要打开我的存放试验代码 ...