题目大意:

要完成两种属性p,q的需求,给定n个双属性物品及其单位个物品中含有的属性,要求选择最少的物品来达成属性需求。(可以选择实数个物品)

题解:

实际上是一种属性混合问题

我们知道对于两种双属性物品,按照一定比例融合

可以配置出的物品的属性在二维平面上的分布一定是一条直线

而这条直线由最初的双属性物品所对应的点坐标所确定

扩展到三个物品,我们发现所有可配置的物品构成了一个三角形

扩展到n个物品,我们发现这n个点构成的凸包内的物品一定都可以配置

所以我们求出凸包来

然后我们从原点想我们的需求对应的点连一条射线

我们发现这条射线会交凸包于两点(?)

我们找出横纵坐标最大的点

此时我们知道:一定是使用配置出这个点的比例来乘以一个系数k来达到我们的需求

这个系数k就是我们的答案

完了么????

还没有

上面打了一个问号,其实是那里有一些问题。。。 。。。

我们发现这样做的话正确性不能保证,这条射线也不一定与凸包相交

... ...

所以我们再加两个点\((max{a_i},0)\)和\((0,max{b_i})\)就行了

... ...

这两个点解决了所有的不妥以及不恰当。

#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 100010;
const double eps = 1e-9;
struct Point{
double x,y;
Point(const double a = .0,const double b = .0){x=a;y=b;}
void print(){
printf("Point (%lf,%lf)\n",x,y);
}
};
typedef Point Vector;
Vector operator + (const Vector &a,const Vector &b){
return Vector(a.x+b.x,a.y+b.y);
}
Vector operator - (const Vector &a,const Vector &b){
return Vector(a.x-b.x,a.y-b.y);
}
double operator * (const Vector &a,const Vector &b){
return a.x*b.y - a.y*b.x;
}
Vector operator * (const Vector &a,const double &b){
return Vector(a.x*b,a.y*b);
}
inline int dcmp(const double &x){
if(x < eps && x > -eps) return 0;
return x > 0 ? 1 : -1;
}
inline bool cmp(const Point &a,const Point &b){
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
int n,m;
Point p[maxn],ch[maxn];
void convex(){
sort(p+1,p+n+1,cmp);m = 0;
for(int i=1;i<=n;++i){
while(m > 1 && dcmp((ch[m] - ch[m-1])*(p[i] - ch[m])) <= 0) -- m;
ch[++m] = p[i];
}int k = m;
for(int i=n-1;i>=1;--i){
while(m > k && dcmp((ch[m] - ch[m-1])*(p[i] - ch[m])) <= 0) -- m;
ch[++m] = p[i];
}swap(n,m);swap(ch,p);
}
Point getPoint(Point p,Vector v,Point q,Vector w){
Vector u = p - q;
double t = (w*u)/(v*w);
return p+v*t;
}
inline double length(const Vector &x){
return sqrt(x.x*x.x+x.y*x.y);
}
#define nx(x) ((x) % n + 1)
bool vis[maxn];
int main(){
int xx,yy;read(n);read(xx);read(yy);
int maxx = 0,maxy = 0;
for(int i=1,x;i<=n;++i){
read(x);p[i].x = x;maxx = max(maxx,x);
read(x);p[i].y = x;maxy = max(maxy,x);
}p[++n] = Point(1.0*maxx,0.0);p[++n] = Point(0.0,1.0*maxy);
convex();Vector v(xx,yy);
Point pos[10];int cnt = 0;
for(int i=1;i<=n;++i){
if(dcmp(v*p[i]) == 0){
vis[i] = true;
pos[cnt++] = p[i];
}
}
for(int i=1;i<=n;++i){
if(vis[i] || vis[nx(i)]) continue;
Point a = p[i],b = p[nx(i)];
if(dcmp(a*v)*dcmp(b*v) <= 0){
pos[cnt++] = getPoint(Point(0,0),v,a,b-a);
}
}
if(cmp(pos[0],pos[1])) swap(pos[0],pos[1]);
double ans = length(v)/length(pos[0]);
printf("%.10lf\n",ans);
getchar();getchar();
return 0;
}

CodeForces - 605C 凸包+直线与凸包判交的更多相关文章

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

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

  2. Codeforces 1017E The Supersonic Rocket 凸包,计算几何,字符串,KMP

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF1017E.html 题目传送门 - CF1017E 题意 给定两个点集,并构成两个凸包. 问这两个凸包是否可 ...

  3. (线段判交的一些注意。。。)nyoj 1016-德莱联盟

    1016-德莱联盟 内存限制:64MB 时间限制:1000ms 特判: No通过数:9 提交数:9 难度:1 题目描述: 欢迎来到德莱联盟.... 德莱文... 德莱文在逃跑,卡兹克在追.... 我们 ...

  4. (叉积,线段判交)HDU1086 You can Solve a Geometry Problem too

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  5. OpenCASCADE直线与平面求交

    OpenCASCADE直线与平面求交 在<解析几何>相关的书中都给出了直线和平面的一般方程和参数方程.其中直线的一般方程有点向式形式的. 由于过空间一点可作且只能作一条直线平行于已知直线, ...

  6. [codeforces/gym/101350/L]维护“凸包”

    题目链接:http://codeforces.com/gym/101350/problems 给定n个墙,每个墙有一个高度,要支持动态修改墙的高度和查询这个“容器”能盛多少水. (队友)观察发现,能盛 ...

  7. $bzoj1007-HAOI2008$ 水平可见直线 下凸包

    题面描述 在\(xOy\)直角坐标平面上有\(n\)条直线\(L_1,L_2,...,L_n\),若在\(y\)值为正无穷大处往下看,能见到\(L_i\)的某个子线段,则称\(L_i\)为可见的,否则 ...

  8. Codeforces 1255F Point Ordering(凸包+叉积)

    我们随机选取点1,2作为凸包的一个分割线,那么我们可以直接枚举剩下n-2个点找到他们和向量1-2的叉积大小与正负,然后我们可以根据叉积的正负,先将他们分割出两个区域,在向量1-2的下方还是上方,接下来 ...

  9. 【BZOJ】1007: [HNOI2008]水平可见直线(凸包)

    题目 传送门:QWQ 分析 在下面维护一个凸壳 好久没写博客了...... 代码 #include <bits/stdc++.h> using namespace std; ; ,INF= ...

随机推荐

  1. python 基础 9.5 数据库连接池

      一. 数据库连接池    python 编程中可以使用MySQLdb 进行数据库的连接及诸如查询,插入,更新等操作,但是每次连接mysql 数据库请求时,都是独立的去请求访问,相当浪费资源,而且访 ...

  2. python 之前函数补充(__del__, item系列, __hash__, __eq__) , 以及模块初体验

    __str__ :  str(obj) ,  需求必须实现了 __str__, 要求这个方法的返回值必须是字符串  str  类型 __repr__ (意为原型输出):  是 __str__ 的备胎( ...

  3. python 写一个类似于top的监控脚本

    最近老板给提出一个需要,项目需求大致如下:      1.用树莓派作为网关,底层接多个ZigBee传感节点,网关把ZigBee传感节点采集到的信息通过串口接收汇总,并且发送给上层的HTTP Serve ...

  4. spring boot mysql和mybatis

    1 选择mysql驱动 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connecto ...

  5. xCode9 一直Indexing

    解决办法:打开终端输入:defaults write com.apple.dt.XCode IDEIndexDisable 1 然后重新打开工程就可以了

  6. python login form

    import time from selenium import webdriver browser = webdriver.Chrome() wait_time = 1 USER = 'xl.fen ...

  7. python基础-第九篇-9.2线程与多线程

    单线程 import time beginTime = time.time() for a in range(10): print(a) time.sleep(1) shijian = time.ti ...

  8. leetcode第一刷_Best Time to Buy and Sell Stock II

    这道题尽管是上一道题的增强.可是反而简单了. 能够交易无数次,可是买卖必须成对的出现. 为了简单起见.我用abc三股股票来说明,且忽略掉相等的情况.三个数一共同拥有六种大小关系.注意他们之间的先后顺序 ...

  9. docker centos yum 源

    aliyun yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.rep ...

  10. bug-4——bootStrap中的table语言设置

    $(document).ready(function() {     $('.datatable').dataTable( {                 "Language" ...