zoukankan      html  css  js  c++  java
  • CCF|碰撞的小球

    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]+"  ");
        }
    }
    

    }

  • 相关阅读:
    vpp编写plugin
    vrf 命令
    vxlan + 多个vrf
    dpdk helloworld
    Go函数高级
    Go_defer
    Go递归函数
    Go作用域
    Go函数
    Go字符串
  • 原文地址:https://www.cnblogs.com/mokero/p/9636327.html
Copyright © 2011-2022 走看看