结合得好巧妙。。。。

化简后的问题是:

给你两个点集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. 【codeforces】【比赛题解】#931 CF Round #468 (Div. 2)

    因为太迟了,所以没去打. 后面打了Virtual Contest,没想到拿了个rank 3,如果E题更快还能再高,也是没什么想法. [A]Friends Meeting 题意: 在数轴上有两个整点\( ...

  2. go 数组

    数组的定义和 初始化 数组是同一类型的元素集合 ]int //定义⼀个数组 Go中数组下标从0开始,因此长度为n的数组下标范围:[0,n-1] 整数数组中的元素默认初始化为0,字符串数组中的元素默认初 ...

  3. 如何编译和安装libevent【转】

    转自:http://www.open-open.com/lib/view/open1455522194089.html 来自: http://blog.csdn.net/yangzhenping/ar ...

  4. 读书笔记 effective c++ Item 48 了解模板元编程

    1. TMP是什么? 模板元编程(template metaprogramming TMP)是实现基于模板的C++程序的过程,它能够在编译期执行.你可以想一想:一个模板元程序是用C++实现的并且可以在 ...

  5. 【前端】h5音乐播放demo 可关闭可播放

    复制如下代码,直接可预览(记得把超链接换成自己本地路径) <!DOCTYPE html> <html> <head> <meta charset=" ...

  6. javaweb笔记一

    内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现 外连接: 包括 (1)左外连接(左边的表不加限制) (2)右外连接(右边的表不加限制) (3)全外连接(左右两表都不加限制 一个空的构造器 ...

  7. 每位架构师都应该熟知的 10 个 SOA 设计模式

    这 10 个 SOA 设计模式是如此之重要,其应用是如此之广泛,以至于它们都有些显而易见了. 1. 服务无关 服务无关实现对多种业务通用的逻辑.将服务无关的逻辑分离成离散的服务以方便服务的重用和整合. ...

  8. 首次加载进来DEV控件列表第一行颜色总是不对,后台代码显示的数据正确

    1:行改变的颜色正确的颜色: 1.1颜色效果如下图: 1.2:设置行改变颜色: 2:结果首次加载第一行颜色为: 3:解决方案: 3.1 :Views-->OptionsSelection --& ...

  9. MySQL学习笔记:delete

    使用 SQL 的 DELETE FROM 命令来删除 MySQL 数据表中的记录. 语法: DELETE FROM table_name [WHERE Clause] 如果没有指定 WHERE 子句, ...

  10. Ansible之迭代、模板

    本节内容: 迭代 模板(JInjia2相关) Jinja2相关 一.迭代 当有需要重复性执行的任务时,可以使用迭代机制.其使用格式为将需要迭代的内容定义为item变量引用,并通过with_items语 ...