结合得好巧妙。。。。

化简后的问题是:

给你两个点集A,B,求B的一个子集BB,使得BB的凸包包含A的凸包,求BB的最小大小。

先特判答案为1,2的情况,答案为3的情况,我们先构造一个有向图:

对于B集合中的两个点u,v,如果 所有A集合的点都在u->v的左侧,那么就连一条u->v的边。

于是我们可以证明一个包含A的凸包和我们连出来的有向图中的环一一对应(不考虑点数小于等于2的情况)。

于是现在我们的问题就是求最小的一个环,用floyd搞,最后统计min(f[i][i])。

 /**************************************************************
Problem: 1027
User: idy002
Language: C++
Result: Accepted
Time:1308 ms
Memory:2008 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define line(a,b) ((b)-(a))
#define eps 1e-8
#define oo 0x3f3f3f3f
#define N 550
using namespace std; int sg( double x ) { return (x>-eps)-(x<eps); }
struct Vector {
double x, y;
Vector(){}
Vector( double x, double y ):x(x),y(y){}
Vector operator-( const Vector &b ) const { return Vector(x-b.x,y-b.y); }
double operator^( const Vector &b ) const { return x*b.y-y*b.x; }
double operator&( const Vector &b ) const { return x*b.x+y*b.y; }
double len() { return sqrt(x*x+y*y); }
bool operator<( const Vector &b ) const {
return sg(x-b.x)< || (sg(x-b.x)== && sg(y-b.y)<);
}
bool operator==( const Vector &b ) const {
return sg(x-b.x)== && sg(y-b.y)==;
}
};
typedef Vector Point; int n, m;
Point aa[N], bb[N];
int dis[N][N]; bool onleft( const Point &a, const Point &b, const Point &c ) {
return sg(line(a,b)^line(a,c))>=;
}
bool onseg( const Point &a, const Point &b, const Point &c ) {
return sg(line(a,b)^line(a,c))== && sg(line(c,a)&line(c,b))<;
}
bool case1() {
if( m== ) {
for( int i=; i<=n; i++ )
if( aa[i]==bb[] )
return true;
}
return false;
}
bool case2() {
bool ok = true;
for( int i=; i<=m && ok; i++ )
for( int j=i+; j<=m && ok; j++ )
for( int k=j+; k<=m && ok; k++ )
if( sg((bb[i]-bb[j])^(bb[k]-bb[j])) )
ok =false;
if( ok ) {
int ii=, jj=;
double ll = -1.0;
for( int i=; i<=m; i++ )
for( int j=i+; j<=m; j++ ) {
double l = (bb[i]-bb[j]).len();
if( l>ll ) {
ii = i;
jj = j;
ll = l;
}
}
for( int i=; i<=n; i++ )
for( int j=i+; j<=n; j++ )
if( onseg(aa[i],aa[j],bb[ii]) && onseg(aa[i],aa[j],bb[jj]) )
return true;
}
return false;
}
int main() {
scanf( "%d%d", &n, &m );
for( int i=; i<=n; i++ ) {
double x, y, z;
scanf( "%lf%lf%lf", &x, &y, &z );
aa[i] = Point(x,y);
}
for( int i=; i<=m; i++ ) {
double x, y, z;
scanf( "%lf%lf%lf", &x, &y, &z );
bb[i] = Point(x,y);
}
sort( bb+, bb++m );
m = unique( bb+, bb++m ) - bb - ;
sort( aa+, aa++n );
n = unique( aa+, aa++n ) - aa - ;
if( case1() ) {
printf( "1\n" );
return ;
} else if( case2() ) {
printf( "2\n" );
return ;
}
memset( dis, 0x3f, sizeof(dis) );
for( int u=; u<=n; u++ )
for( int v=; v<=n; v++ ) {
if( u==v ) continue;
bool ok = true;
for( int k=; k<=m; k++ )
if( !onleft(aa[u],aa[v],bb[k]) ) {
ok = false;
break;
}
if( ok ) {
dis[u][v] = ;
}
}
for( int k=; k<=n; k++ )
for( int i=; i<=n; i++ )
for( int j=; j<=n; j++ )
dis[i][j] = min( dis[i][j], dis[i][k]+dis[k][j] );
int ans = oo;
for( int i=; i<=n; i++ ) {
if( dis[i][i]== ) continue;
ans = min( ans, dis[i][i] );
}
printf( "%d\n", ans==oo ? - : ans );
}

bzoj 1027 floyd求有向图最小环的更多相关文章

  1. UVa 247 - Calling Circles(Floyd求有向图的传递闭包)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  2. FZU 2090 旅行社的烦恼 floyd 求无向图最小环

    题目链接:旅行社的烦恼 题意是求无向图的最小环,如果有的话,输出个数,并且输出权值. 刚刚补了一发floyd 动态规划原理,用了滑动数组的思想.所以,这个题就是floyd思想的变形.在k从1到n的过程 ...

  3. poj1734 Sightseeing trip(Floyd求无向图最小环)

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

  4. hdu 1599 find the mincost route floyd求无向图最小环

    find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  5. 【BZOJ 1027】 (凸包+floyd求最小环)

    [题意] 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金 ...

  6. floyd求最小环 模板

    http://www.cnblogs.com/Yz81128/archive/2012/08/15/2640940.html 求最小环 floyd求最小环 2011-08-14 9:42 1 定义: ...

  7. 2017"百度之星"程序设计大赛 - 资格赛【1001 Floyd求最小环 1002 歪解(并查集),1003 完全背包 1004 01背包 1005 打表找规律+卡特兰数】

    度度熊保护村庄 Accepts: 13 Submissions: 488 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3276 ...

  8. Floyd求最小环!(转载,非原创) 附加习题(原创。)HDU-1599

    //Floyd 的 改进写法可以解决最小环问题,时间复杂度依然是 O(n^3),储存结构也是邻接矩阵 int mincircle = infinity; Dist = Graph; ;k<nVe ...

  9. 2018.09.15 hdu1599find the mincost route(floyd求最小环)

    传送门 floyd求最小环的板子题目. 就是枚举两个相邻的点求最小环就行了. 代码: #include<bits/stdc++.h> #define inf 0x3f3f3f3f3f3f ...

随机推荐

  1. 使用qt写的进制转换器

    没有使用什么数据结构,直接使用qt自带的进制转换函数, 实时出结果,代码在后面的链接中,由于初学qt,好多不会,代码构造就有点乱 截图如下

  2. input 标签禁止输入

    1.鼠标可以点击输入框,但是不能输入 readonly 例如: <input class="layui-input" readonly > 2.鼠标点击输入框出现禁用图 ...

  3. 聊天室(上篇)GatewayWorker 基础

    前言 本文的目的是基于 GatewayWorker 官方手册,梳理一次 GatewayWorker,并在实践中与 MVC 框架整合的思路(附最终的项目源码).如果你已经理解了整合这一块儿的知识,那么就 ...

  4. Flask--wtforms快速使用和表单验证(附示例)

    一.Form类 表单提供WTForms中最高级别的API.它们包含您的字段定义,委托验证,获取输入,聚合错误,并且通常用作将所有内容组合在一起的粘合剂. class wtforms.form.Form ...

  5. 数据库-mysql数据类型

    MySQL 数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的. MySQL支持多种类型,大致可以分为三类:数值.日期/时间和字符串(字符)类型. 数值类型 MySQL支持所有标准S ...

  6. React 学习一 运行

    最近项目准备使用React作为前端,主要第一比较火,第二比较小.抽空先来学习一下. 首先下载资源文件:压缩后不到50KB,是挺小的哦. 其中:react.js 是 React 的核心库,react-d ...

  7. Python *args **kw

    当函数的参数不确定时,可以使用*args 和**kwargs,*args 没有key值,**kwargs有key值. *args def fun_var_args(farg, *args): prin ...

  8. 树莓派3B更换源为阿里源

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #科大源 sudo nano /etc/apt/sources.list deb htt ...

  9. appium----adb shell输入中文/Emoji表情符(ADBKeyBoard)

    前序 “adb shell input textyoyo“ 可以通过adb 输入英文的文本,由于不支持unicode编码,所以无法输入中文,github上有个国外的大神写了个ADBKeyBoard输入 ...

  10. mysql 5.1 下载地址 百度云网盘下载

    mysql 百度云下载 链接: https://pan.baidu.com/s/1fPSEcgtDN7aU2oQ_sL08Ww 提取码: 关注公众号[GitHubCN]回复2539获取