#include<stdio.h>
#include<stdlib.h>
#include<math.h>
typedef struct tag_point_t
{
double x, y;
}point_t;
#define POINT_NUM 30
double calc_distance(const point_t *p, const point_t *q)
{
double dx, dy;
dx=p->x-q->x;
dy=p->y-q->y;
return sqrt(dx
*dx
+dy
*dy
); }
int main(void)
{
point_t point[POINT_NUM];
unsigned long connection[POINT_NUM], A_connection;
int i, j, is_changed, A, B;
for(i=0;i<POINT_NUM;i++)
{
point
[i
].
x=rand()/(RAND_MAX
+1.0)*10.0; point
[i
].
y=rand()/(RAND_MAX
+1.0)*10.0; connection[i]=0;
}
do
{
}while(A==B);
for(i=0;i<POINT_NUM;i++)
{
for(j=i;j<POINT_NUM;j++)
{
if(calc_distance(&point[i], &point[j])<=10.0)
{
connection[i]|=(1<<j);
connection[j]|=(1<<i);
}
}
}
A_connection=connection[A];
do
{
is_changed=0;
for(i=0;i<POINT_NUM;i++)
{
if(((A_connection>>i)&1) && ((A_connection&connection[i])!=connection[i]))
{
A_connection|=connection[i];
is_changed=1;
}
}
}while(is_changed);
for(i=0;i<POINT_NUM;i++)
{
printf("%2d : (%f,%f)\n", i
, point
[i
].
x, point
[i
].
y); }
printf("移動%s\n", ((A_connection
>>B
)&1)?"可能":"不可能");
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPG1hdGguaD4KCnR5cGVkZWYgc3RydWN0IHRhZ19wb2ludF90CnsKICAgIGRvdWJsZSB4LCB5Owp9cG9pbnRfdDsKCiNkZWZpbmUgUE9JTlRfTlVNIDMwCgpkb3VibGUgY2FsY19kaXN0YW5jZShjb25zdCBwb2ludF90ICpwLCBjb25zdCBwb2ludF90ICpxKQp7Cglkb3VibGUgZHgsIGR5OwoKCWR4PXAtPngtcS0+eDsKCWR5PXAtPnktcS0+eTsKCXJldHVybiBzcXJ0KGR4KmR4K2R5KmR5KTsKfQoKaW50IG1haW4odm9pZCkKewoJcG9pbnRfdCBwb2ludFtQT0l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TsKCX0KCXByaW50ZigiQT0lZCAgQj0lZFxuIiwgQSwgQik7CgoJcHJpbnRmKCLnp7vli5Ulc1xuIiwgKChBX2Nvbm5lY3Rpb24+PkIpJjEpPyLlj6/og70iOiLkuI3lj6/og70iKTsKCglyZXR1cm4gMDsKfQo=
0 : (8.401877,3.943829)
1 : (7.830992,7.984400)
2 : (9.116474,1.975514)
3 : (3.352228,7.682296)
4 : (2.777747,5.539700)
5 : (4.773971,6.288709)
6 : (3.647845,5.134009)
7 : (9.522297,9.161951)
8 : (6.357117,7.172969)
9 : (1.416026,6.069689)
10 : (0.163006,2.428868)
11 : (1.372316,8.041768)
12 : (1.566791,4.009444)
13 : (1.297904,1.088088)
14 : (9.989245,2.182569)
15 : (5.129324,8.391122)
16 : (6.126398,2.960316)
17 : (6.375523,5.242872)
18 : (4.935830,9.727750)
19 : (2.925168,7.713577)
20 : (5.267450,7.699138)
21 : (4.002286,8.915295)
22 : (2.833147,3.524583)
23 : (8.077245,9.190265)
24 : (0.697553,9.493271)
25 : (5.259953,0.860558)
26 : (1.922138,6.632269)
27 : (8.902326,3.488929)
28 : (0.641713,0.200230)
29 : (4.577017,0.630958)
A=15 B=14
移動可能