结合得好巧妙。。。。

化简后的问题是:

给你两个点集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. 我应该记录一下我不太了解的一些c语言函数

    当然,现在还不分类 fmemopen getpagesize()

  2. 利用rundll32执行程序的函数执行程序

    1.前言 无意间发现hexacorn这个国外大佬,给出了很多通过rundll32执行DLL中的函数执行程序的方法,思路很灵巧. 2.原理 rundll32加载dll 用法: rundll32 < ...

  3. ispoweroftwo 判断2的次幂

    首先结果是: public bool IsPowerOfTwo(int n) { if(n<1) return false;//2的次幂一定大于0 return ((n & (n -1) ...

  4. 牛x的JavaScript编辑器你知道几个

    英文:Martin Heller  译文:葡萄城控件 学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入学习交流群343599877,我们一起学前端! 对于JavaScript程序员来说,目前有很 ...

  5. Python 常用的内建函数

    内建函数 ​ Build-in Function,启动python解释器,输入dir(__builtins__), 可以看到很多python解释器启动后默认加载的属性和函数,这些函数称之为内建函数, ...

  6. mybatis 易百练习笔记

    1. session.commit()  增删改需要提交     session.close()    session需要关闭 2. insert  into t()   values()  不用写i ...

  7. 关于int *a; int &a;a; int &a; *a; int * &a

    int i; int*a =&i;//这里a是一个指针,它指向变量i int&b = i;//这里b是一个引用,它是变量i的引用,引用是什么?它的本质是什么?下面会具体讲述 int*& ...

  8. babel转换不了有些es6

    bable只转换新语法 不支持新的全局变量如promise async等等,可以使用babel-polyfilll来兼容

  9. Python创建ES索引

    # pip install elasticsearch from datetime import datetime from elasticsearch import Elasticsearch es ...

  10. Rewrite HTTP to HTTPS in Nginx

    1.推荐配置 server { listen 80; server_name example1.com example2.com; return 301 https://$host$request_u ...