球和篮筐问题算法?篮筐、算法、问题

2023-09-11 06:50:34 作者:待你如故

假设有N多人,所有这些人都1筐和无限的球。 他们可以丢一球,以别人的篮子。

Let's say there are N people and all these people have 1 basket and unlimited balls. They can throw a ball to others' baskets.

我们让他们扔球,以别人的篮子,我们想出了这样的情景:

We let them throw their balls to others' baskets and we come up with a scenario like that :

A人的篮子 从E,F,G,I,K,L,M,P球

'A' person's basket Balls from E, F, G, I, K, L, M, P

B人的篮子 从A,C,E,F,K,T,R,Z

'B' person's basket Balls from A, C, E, F, K, T, R, Z

C人的篮子 从球......

'C' person's basket Balls from ......

等等...

所以我想设计一个算法来找出哪些是朋友。例如,如果A,C,D和E是朋友,他们应该抛出自己的球,对方的篮子。但在同一时间,他们可以抛出一些随机的陌生人的篮下了。

so I want to design an algorithm to find out which ones are friends. For example if A, C, D and E are friends they should throw their balls to each others' baskets. But at the same time they can throw some random stranger's basket too.

我知道这是一个优化的问题,没有一个spesific解决方案,但我接受任何想法从头再来。

I know it is an optimization problem, there is not a spesific solution but I'm open to any idea to start over.

感谢。

推荐答案

朋友将可能给对方一个球 - 有一个伟大的起点

Friends will probably give each other a ball - there's a great starting point.

for x,y in people:
    if (x contains y && y contains x):
        x & y are friends.
    else:
        skip.

粗糙的伪code,写在你所知道的。

Rough pseudocode, write it in what you know.

这仅仅是个开始,虽然,你应该看看集群朋友淘汰的巧合,加入被遗忘的朋友。

That's only the beginning though, you should probably look at clusters of friends to weed out coincidences and add in forgotten friends.