UVa10881 Piotr's Ants

这里写自定义目录标题

Piotr likes playing with ants. He has n of them on a horizontal poleL cm long.
Each ant is facing either left or right and walks at a constant speed of 1 cm/s.
When two ants bump into each other, they both turn around (instantaneously) and
start walking in opposite directions. Piotr knows where each of the ants starts
and which direction it is facing and wants to calculate where the ants will end
upT seconds from now.

import random

Piotr_ants=[]
Piotr_ants_flag=[]
Flag=[-1.0,1.0]

Ants_number=100
Pole_length=200
Time=40



while(len(Piotr_ants)
import random

Piotr_ants=[]
Piotr_ants_flag=[]
Flag=[-1.0,1.0]

Ants_number=10
Pole_length=2000
Time=1000

while(len(Piotr_ants)
import random

Piotr_ants=[]
Piotr_ants_flag=[]
Flag=[-1.0,1.0]

Ants_number=200
Pole_length=20000
Time=10000

while(len(Piotr_ants)0):
        Ant_last_left=Ant_last_left-1
    print("Ant_first_right is :",Ant_first_right)
    print("Ant_last_left is",Ant_last_left)

    Min_distance=Pole_length*Time    
    for i in range(Ant_first_right,Ant_last_left):
        if abs(Piotr_ants_flag[i]-Piotr_ants_flag[i+1]-2.0)<0.001:
            Min_distance=min(Min_distance,Piotr_ants[i+1]-Piotr_ants[i])
##        print("the Min_dastance is:",Min_distance,"at",i)
    t_Delta=Min_distance/2.0

  
    t=t+t_Delta
    for i in range(Ants_number):
        Piotr_ants[i]=Piotr_ants[i]+t_Delta*Piotr_ants_flag[i]

    for i in range(Ant_first_right,Ant_last_left):
        if abs(Piotr_ants[i]-Piotr_ants[i+1])<0.001:
            Piotr_ants_flag[i]=-1.0
            Piotr_ants_flag[i+1]=1.0
    print("time is:",t)
print(Piotr_ants)
print(Piotr_ants_flag)

你可能感兴趣的:(UVa10881 Piotr's Ants)