[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 ...
随机推荐
- python学习笔记2-字符串操作
一.字符串切片 #切片也能适合字符串 tittle='今 天 发 苹 果' for i t in enumerate(tittle): #enumerate可以同时循环下标和值 print('%s:% ...
- Java并发编程原理与实战十一:锁重入&自旋锁&死锁
一.锁重入 package com.roocon.thread.t6; public class Demo { /* 当第一个线程A拿到当前实例锁后,进入a方法,那么,线程A还能拿到被当前实例所加锁的 ...
- soj1022. Poor contestant Prob
1022. Poor contestant Prob Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description As everyb ...
- getElementById()方法取值
举例子: javascript: var time = document.getElementById('jidu').value; //指定时间 var taskclass = document.g ...
- HDU 6096 String (AC自动机)
题目链接 Problem Description Bob has a dictionary with N words in it. Now there is a list of words in wh ...
- 【译】第八篇 Integration Services:高级工作流管理
本篇文章是Integration Services系列的第八篇,详细内容请参考原文. 简介在前面两篇文章,我们创建了一个新的SSIS包,学习了SSIS中的脚本任务和优先约束,并检查包的MaxConcu ...
- UNIX环境高级编程 第7章 进程环境
本章涉及C/C++程序中main函数是如何被调用的.命令行参数如何传递给main函数.程序的内存空间布局.程序如何使用环境变量.程序如何终止退出. main函数 C程序或C++程序总是从main函数开 ...
- 突破XSS字符限制执行任意JS代码
突破XSS字符限制执行任意JS代码 一.综述 有些XSS漏洞由于字符数量有限制而没法有效的利用,只能弹出一个对话框来YY,本文主要讨论如何突破字符数量的限制进行有效的利用,这里对有效利用的定义是可以不 ...
- ActiveMQ与SpringMVC整合实现发送PTP和订阅发布消息功能
实现一个基于SpringMVC+JMS+ActiveMQ+Tomcat+JDK1.8+IDEA工具 ,Spring4.1.0和ActiveMQ5.15整合的实例,实现PTP和订阅/发布两种消息模型 一 ...
- 冲量:momentum
参见:http://www.jianshu.com/p/58b3fe300ecb,这个博客里有冲量的python实现的代码和讲解 “冲量”这个概念源自于物理中的力学,表示力对时间的积累效应. 在普通的 ...