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. 实现Asp.Net Mvc4多级Views目录

    建立自己MyViewEngine类让他继承RazorViewEngine,之后在构造函数里面写入设置视图位置格式代码如下: public class MyViewEngine : RazorViewE ...

  2. Windows 删除 .svn标志

    之前一个项目是在SVN下面管理的,后来,考出来了,然后在Eclispe中使用,后来想用SVN管理起来,但是项目中,还是有.svn标志,只能先删除了.svn文件,然后在用svn管理起来,后来,发现.sv ...

  3. iOS-Runtime-Headers

    iOS8.4 及之前的头文件 私有及共有API https://github.com/nst/iOS-Runtime-Headers  

  4. vector reserve与resize区别

    vector 的reserve增加了vector的capacity,但是它的size没有改变!而resize改变了vector的capacity同时也增加了它的size!原因如下:reserve是容器 ...

  5. Good Bye 2015B(模拟或者二进制枚举)

    B. New Year and Old Property time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. poj 3461Oulipo

    题目链接:http://poj.org/problem?id=3461 统计字符串出现的次数 #include<cstdio> #include<iostream> #incl ...

  7. bnuoj 24251 Counting Pair

    一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...

  8. mysql的事务处理

    事务用于保证数据的一致性,它由一组相关的DML语句组成,该组的DML语句要么全部成功,要么全部失败. 示例: 银行账单 $mysqli=new mysqli("localhost" ...

  9. C#调用C++DLL的小总结5---和C++的DLL的联合调试

    http://fpcfjf.blog.163.com/blog/static/5546979320134922938373/ http://blog.csdn.net/jiangxinyu/artic ...

  10. jquery学习笔记----jquery相关的文档

    http://tool.oschina.net/apidocs/apidoc?api=jquery http://www.w3school.com.cn/jquery/jquery_ref_event ...