1. 程式人生 > >CCF|碰撞的小球

CCF|碰撞的小球

int() oid str system static all util ring i++

import java.util.Scanner;

public class Main
{
public static void main (String[] args)
{
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int L=scanner.nextInt();
int t=scanner.nextInt();
int[] ball=new int[n];
int[] speeds=new int[n];

    for(int i=0;i<n;i++)
    {
        ball[i]=scanner.nextInt();
    }
    for(int i=0;i<n;i++)
    {
        speeds[i]=1;
    }
    for(int i=0;i<t;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(ball[j]==L)
            {
                speeds[j]=-1;
            }
            else if(ball[j]==0)
            {
                speeds[j]=1;
            }
            for (int k=0;k<n;k++)
            {
                if(j!=k&&ball[j]==ball[k])
                {
                    speeds[j]*=(-1);
                    speeds[k]*=(-1);
                }
            }
            ball[j]+=speeds[j];
        }
    }
    for (int i=0;i<n;i++)
    {
        System.out.printf(ball[i]+"  ");
    }
}

}

CCF|碰撞的小球