结合得好巧妙。。。。

化简后的问题是:

给你两个点集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. perl6 Net::HTTP 发送任意 url 请求例子

    只做个笔记, 用 HTTP::UserAgent 的话, url 中有特殊点的符号会请求不了, 用 Net::HTTP 能很好的发送请求. use Net::HTTP::GET; my $url = ...

  2. verilog中wire与reg类型的区别

    每次写verilog代码时都会考虑把一个变量是设置为wire类型还是reg类型,因此把网上找到的一些关于这方面的资料整理了一下,方便以后查找. wire表示直通,即只要输入有变化,输出马上无条件地反映 ...

  3. MySQL 5.7以后怎么查看索引使用情况?

    MySQL 5.7以后怎么查看索引使用情况? 0.在sys库中查看没用的索引 root@localhost [sys]>select * from schema_unused_indexes; ...

  4. ### mysql系统结构_3_Mysql_Learning_Notes

    mysql系统结构_3_Mysql_Learning_Notes 存储层,内存结构 全局(buferpool) 只分配一次 全局共享 连接/会话(session) 针对每个会话/线程分配 按需动态分配 ...

  5. hibernate学习之一 框架配置

    hibernate 框架 1.hibernate框架应用在javaee三层结构中的dao层框架 2.好处就是不需要写复杂jdbc代码,不需要sql语句实现 3.是开源的轻量级框架 hibernate使 ...

  6. 31 Godoc: documenting Go code 编写良好的文档关于godoc

    Godoc: documenting Go code  编写良好的文档关于godoc 31 March 2011 The Go project takes documentation seriousl ...

  7. CSS--布局模型,颜色值,长度值

    目录 布局模型 流动模型(Flow) 浮动模型 (Float) 层模型(Layer) 颜色值 长度值  一.布局模型 网页布局模型:个人理解,就是对html中各个元素进行一个排列.而排列的方法可以分为 ...

  8. 浅谈js变量作用域

    变量的作用域也是前端面试题常考的一个问题,掌握下面几个规律可以帮你更好的理解js的作用域. 1.作用域优先级遵循就近原则,函数内部的作用域优先级大于外部 var a=456; var b=111; f ...

  9. java基础65 JavaScript中的Window对象(网页知识)

    1.javaScript组成部分 1.EMCAScript(基本语法)    2.BOM(Browser Object Model):浏览器对象模型            浏览器对象模型中的浏览器的各 ...

  10. 你竟然在公钥中下毒!——如何在RSA公钥中添加后门

    原文:http://www.hackdig.com/?01/hack-17893.htm 分享到: 当我知道它是如何运行时,我惊得下巴都掉了.这是一个非常简单的手法,但这篇文章会颠覆你之前对RSA的看 ...