结合得好巧妙。。。。

化简后的问题是:

给你两个点集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. Tslib移植与分析【转】

    转自:http://blog.csdn.net/water_cow/article/details/7215308 目标平台:LOONGSON-1B开发板(mips32指令集)编译平台:x86PC-- ...

  2. aarch64_m2

    mingw32-leptonica-1.74.4-1.fc26.noarch.rpm 2017-06-12 17:20 1.0M fedora Mirroring Project mingw32-le ...

  3. Linux的bg和fg命令 ---让程序在前台后台之间切换

    Linux的bg和fg命令 我们都知道,在 Windows 上面,我们要么让一个程序作为服务在后台一直运行,要么停止这个服务.而不能让程序在前台后台之间切换.而 Linux 提供了 fg 和 bg 命 ...

  4. MVVM设计模式的事件绑定

    为什么要事件绑定 这个问题其实是很好理解的,因为事件是丰富多样的,单纯的命令绑定远不能覆盖所有的事件.例如Button的命令绑定能够解决Click事件的需求,但Button的MouseEnter.窗体 ...

  5. Windows版Oracle重建EM---备注

    前提条件添加环境变量 ORACLE_HOSTNAME=<主机名:如:DESKTOP-P6J1a>ORACLE_SID=orclORACLE_UNQNAME=orcl 执行删除命令 C:\U ...

  6. parseObject方法将json字符串转换成Map

    String nwVal=recordDO.getWorkOrderNwVal(); HashMap<String,WxhcWorkOrderDO> nwMap=JSON.parseObj ...

  7. [how to]HBase Snapshots原理与使用

    1.简介 Snapshots即快照的意思,作用于表上.在对于表做快照的时候不会造成文件的拷贝,如不会对HFile文件进行拷贝而是以链接的方式链接到元表的HFile上.可以说它是一种元数据的集合,可以快 ...

  8. linux查看内存、CPU占用资源最多的进程

    [内存占用] #利用ps命令,默认使用ps参数会显示的结果 ps -aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 ...

  9. scala可变长度参数(转)

    可变长度参数 Scala 允许你指明函数的最后一个参数可以是重复的.这可以允许客户向函数传入可变长度参数列表.想要标注一个重复参数,在参数的类型之后放一个星号.例如: scala> def ec ...

  10. 洛谷P1841重要的城市

    传送门啦 重要城市有三个性质如下: 1.重要城市能对其他两个不同城市的最短路径做出贡献 2.重要城市具有唯一性,如果两不同城市之间的最短路径有两种中间城市情况,那么这两个中间城市可以彼此代替,就都不能 ...