【bzoj1027】合金

  • 本文为博主原创,未经许可不得转载

好有趣的题目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
#define FILE "read"
#define MAXN 510
#define eps 1e-8
#define INF 1e9
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
using namespace std;
struct Point{
double x,y;
Point(double a=0,double b=0):x(a),y(b){}
inline void read(){scanf("%lf%lf%*lf",&x,&y);}
inline Point operator+(const Point &b){return Point(x+b.x,y+b.y);}
inline Point operator-(const Point &b){return Point(x-b.x,y-b.y);}
inline Point operator*(const double p){return Point(x*p,y*p);}
inline Point operator/(const double p){return Point(x/p,y/p);}
}A[MAXN],B[MAXN];
int n,m,ans,f[MAXN][MAXN];
inline double Dot(Point A,Point B){return A.x*B.x+A.y*B.y;}
inline double Cross(Point A,Point B){return A.x*B.y-A.y*B.x;}
inline int dcmp(double x){
if(fabs(x)<eps) return 0;
else return x<0?-1:1;
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
scanf("%d%d",&n,&m); ans=INF; memset(f,10,sizeof(f));
for(int i=1;i<=n;++i) A[i].read();
for(int i=1;i<=m;++i) B[i].read();
for(int i=1;i<=n;++i)for(int j=1;j<=n;++j){
bool flag=1;
for(int k=1;k<=m;++k){
if(dcmp(Cross(A[i]-B[k],A[j]-B[k]))>0){flag=0;break;}
if(dcmp(Cross(A[i]-B[k],A[j]-B[k]))==0&&dcmp(Dot(A[i]-B[k],A[j]-B[k]))>0){flag=0;break;}
}
if(flag) f[i][j]=1;
}
for(int k=1;k<=n;++k)for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)
cmin(f[i][j],f[i][k]+f[k][j]);
for(int i=1;i<=n;++i)cmin(ans,f[i][i]);
if(ans>n) puts("-1");
else printf("%d\n",ans);
return 0;
}
文章目录
,