[CodeForces-606E] Freelancer's Dreams 凸包 模型转换
大致题意:
有一个人想要获得p个经验点和q元钱。现在给出n份工作,每份工作每天能得到Ai的经验值和Bi的钱,问最少需要工作多少天,
能使得总经验值>=p,总钱>=q。
先对给出的n份工作以及原点O(0,0),x轴的最大点(maxx,0),y轴最大点(0,maxy)构建凸包,根据凸组合,可知凸包上所有得点以
及凸包边上的点都可以由一天时间得到,那么只要求出射线O~P(p,q)与凸包的交点,即可求出最后的结果。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 200100
#define eps 1e-5
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e9+9
#define Vector Point
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
struct Point {
double x,y;
int id;
int pre,nxt;
Point(double x=,double y=) : x(x),y(y) {}
Point operator - (const Point &a)const{ return Point(x-a.x,y-a.y); }
Point operator + (const Point &a)const{ return Point(x+a.x,y+a.y); }
Point operator * (const double &a)const{ return Point(x*a,y*a); }
Point operator / (const double &a)const{ return Point(x/a,y/a); }
bool operator < (const Point &a)const{ if(x==a.x) return y<a.y;return x<a.x; }
bool operator == (const Point &a)const{ return dcmp(x-a.x)== && dcmp(y-a.y)==; }
void read(int iid=) { scanf("%lf%lf",&x,&y);id=iid; }
void out(){cout<<"Bug: "<<x<<" "<<y<<endl;}
};
inline double Cross(Vector a,Vector b) { return a.x*b.y-a.y*b.x; }
inline double Dot(Vector a,Vector b) { return a.x*b.x+a.y*b.y; }
inline double dis(Vector a) { return sqrt(Dot(a,a)); }
int ConvexHull(Point *p,int n,Point *ch){
int m=;
sort(p,p+n);
For(i,,n-){
p[i].id=i;
while(m> && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
int k=m;
Fore(i,n-,){
while(m>k && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
return m;
}
inline bool Onsegment(Point a,Point b1,Point b2){
return dcmp(Cross(b1-a,b2-a))== && dcmp(Dot(b1-a,b2-a))<;
}
bool Intersect_Segm_Ray(Point a1,Vector u,Point b1,Point b2){
double c1=Cross(b1-a1,u),c2=Cross(b2-a1,u);
if(dcmp(c2)*dcmp(c1)>) return ;
if(dcmp(c2)*dcmp(c1)<){
c1=Dot(b1-a1,u);c2=Dot(b2-a1,u);
return dcmp(c1)>= && dcmp(c2)>=;
}
if(c1==) return dcmp(Dot(b1-a1,u))>;
if(c2==) return dcmp(Dot(b2-a1,u))>;
}
Point Intersect_Line_Point(Point p,Vector u,Point q,Vector v){
Vector w=p-q;
double t=Cross(v,w)/Cross(u,v);
return p+u*t;
}
int n;
double maxx,maxy;
Point p[MAXN],cp;
Point ch[MAXN];
int solve(){
double ans=inf;maxx=;maxy=;
cin>>n;cp.read();
For(i,,n-) p[i].read(),maxx=max(p[i].x,maxx),maxy=max(p[i].y,maxy);
p[n]=Point(,);
p[n+]=Point(,maxy);
p[n+]=Point(maxx,);
int m=ConvexHull(p,n+,ch);
For(i,,m-){
if(ch[i]==Point(,) || ch[(i+)%m]==Point(,)) continue;
if(Intersect_Segm_Ray(Point(,),cp,ch[(i+)%m],ch[i])){
Point st=Intersect_Line_Point(cp,cp,ch[i],ch[(i+)%m]-ch[i]);
ans=min(ans,dis(cp)/dis(st));
}
}
printf("%.15lf\n",ans);
}
int main(){
// fre("in.txt","r",stdin);
int t=;
while(t--)solve();
return ;
}
[CodeForces-606E] Freelancer's Dreams 凸包 模型转换的更多相关文章
- Codeforces 605C Freelancer's Dreams 凸包 (看题解)
Freelancer's Dreams 我们把每个二元组看成是平面上的一个点, 那么两个点的线性组合是两点之间的连线, 即x * (a1, b1) + y * (a1, b1) && ...
- 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 ...
- CF#335 Freelancer's Dreams
Freelancer's Dreams time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 前端MVVM框架avalon - 模型转换1
轻量级前端MVVM框架avalon - 模型转换(一) 接上一章 ViewModel modelFactory工厂是如何加工用户定义的VM? 附源码 洋洋洒洒100多行内部是魔幻般的实现 1: fun ...
- 将List 中的ConvertAll的使用:List 中的元素转换,List模型转换, list模型转数组
一,直接入代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using S ...
- Verification of Model Transformations A Survey of the State-of-the-Art 模型转换的验证 对现状的调查
模型驱动工程范式认为软件开发生命周期由工件(需求规范.分析和设计文档.测试套件.源代码)支持,这些工件是表示要构建的系统不同视图的模型.存在一个由模型转换驱动的(半)自动构造过程,从系统的抽象模型开始 ...
- 【tensorflow-v2.0】如何将模型转换成tflite模型
前言 TensorFlow Lite 提供了转换 TensorFlow 模型,并在移动端(mobile).嵌入式(embeded)和物联网(IoT)设备上运行 TensorFlow 模型所需的所有工具 ...
- 洛谷P1155 双栈排序题解(图论模型转换+二分图染色+栈)
洛谷P1155 双栈排序题解(图论模型转换+二分图染色+栈) 标签:题解 阅读体验:https://zybuluo.com/Junlier/note/1311990 原题地址:洛谷P1155 双栈排序 ...
- 【机器学习】使用CNN神经网络实现对图片分类识别及模型转换
仅做记录,后面慢慢整理 训练函数: from skimage import io, transform # skimage模块下的io transform(图像的形变与缩放)模块 import glo ...
随机推荐
- SSM简单整合教程&测试事务
自打来了博客园就一直在看帖,学到了很多知识,打算开始记录的学习到的知识点 今天我来写个整合SpringMVC4 spring4 mybatis3&测试spring事务的教程,如果有误之处,还请 ...
- MapReduce (MRV1)设计理念与基本架构
MapReduce 是一个分布式计算框架,主要由两部分组成:编程模型和运行时环境. 其中,编程模型为用户提供了非常易用的编程接口,用户只需要像编写串行程序一样实现几个简单的函数即可实现一个分布式程序, ...
- asp启用父路径
开启父路径后可以用../来表示上一层目录,如果网站程序中使用了../,不开启则网站程序里有../就会报错. IIS6启用父路径方法:打开IIS管理器——网站——右键属性——主目录——配置——选项——选 ...
- #Fixed# easy-animation | Animation for Sass
原文链接:http://www.cnblogs.com/maplejan/p/3659830.html 主要修复3.4版本后变量作用域的问题. 代码如下: /* easy-animation.scss ...
- 超酷JQuery动画分页按钮,鼠标悬停滑动展开
1.效果及功能说明 animate动画分页按钮制作鼠标悬停分页按钮上滑动展开分页按钮,鼠标离开后分页按钮收缩 2.实现原理 主要是靠动画方法,来让原本的箭头图像的长度发生变长,正好可以融入下标题的文字 ...
- 【leetcode 简单】 第一百零八题 找到所有数组中消失的数字
给定一个范围在 1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次. 找到所有在 [1, n] 范围之间没有出现在数组中的数字. 您能在不 ...
- 【蓝桥杯单片机12】实时时钟DS1302的基本操作
[蓝桥杯单片机12]实时时钟DS1302的基本操作 广东职业技术学院 欧浩源 实时时钟DS1302几乎是蓝桥杯“单片机设计与开发”每年必考的内容,虽然在竞赛现场有提供一个底层读写寄存器的库文件,但是作 ...
- 动态获取UILabel的bounds
在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法. 1.获取宽度,获取字符串不折行单行显示时所需要的长度 CGSize labelBounds = [s ...
- 利用SSLStrip截获https协议--抓取邮箱等密码
1.SSL解析 SSL 是 Secure Socket Layer 的简称, 中文意思是安全套接字层,由 NetScape公司所开发,用以保障在 Internet 上数据传输的安全,确保数据在网络的传 ...
- 【NOI题解】【bzoj题解】NOI2008 bzoj1063 道路设计
@ACMLCZH学长出的毒瘤题T3.再也不是“善良”的出题人了. 题意:bzoj. 题解: 经典的树形DP题目,屡见不鲜了,然而我还是没有写出来. 这一类的题目有很多,例如这里的C题. 主要套路是把对 ...