# 【BZOJ 1027】[JSOI2007]合金

【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1027

【题意】

【题解】

(ap1+bp2)/(a+b)
=q*p1+w*p2;

(可以证明只要闭包包住了S2,则S2里面的点集都能得到);

(很懒并没有加上)

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 510;
const int INF = 0x3f3f3f3f;

struct point
{
double x, y;
point operator -(const point z)
{
point re;
re.x = x - z.x;
re.y = y - z.y;
return re;
}
double operator * (const point z)
{
return x*z.y - y*z.x;
}
double operator ^ (const point z)
{
return x*z.x + y*z.y;
}
} a[N], b[N];

int m, n;
int d[N][N], f[N][N];
int ans = INF;

void input_data()
{
rei(m), rei(n);
double t;
rep1(i, 1, m)
{
ref(a[i].x), ref(a[i].y), ref(t);
}
rep1(i, 1, n)
{
ref(b[i].x), ref(b[i].y), ref(t);
}
}

void ga()
{
memset(d, 0x3f, sizeof d);
rep1(i,1,m)
rep1(j, 1, m)
{
int k;
for (k = 1; k <= n;k++)
{
double cross = (a[i] - b[k])*(a[j] - b[k]);
if (cross > 1e-7)
break;
if (fabs(cross) < 1e-7 && (a[i] - b[k] ^ a[j] - b[k]) > 1e-7)
break;
}
if (k == n + 1)
d[i][j] = 1;
}

}

void fl()
{
memcpy(f, d, sizeof f);
rep1(k,1,m)
rep1(i,1,m)
if (f[i][k]<INF)
rep1(j, 1, m)
{
f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
}
rep1(i, 1, m)
ans = min(ans, f[i][i]);
}

void o()
{
if (ans == INF)
{
puts("-1");
return;
}
printf("%d\n", ans);
}

int main()
{
//freopen("F:\\rush.txt", "r", stdin);
input_data();
ga();
fl();
o();
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

posted @ 2017-10-04 18:45  AWCXV  阅读(145)  评论(0编辑  收藏  举报