zoukankan      html  css  js  c++  java
  • Ants-穷举算法

    package java操作excel;
    
    import java.util.Scanner;
    
    
    /**
     * Ants
     * n只蚂蚁以每秒1cm的速度在长为Lcm的竿子上爬行,当蚂蚁爬到端点就会掉下去,竿子细两只蚂蚁不能交错通过,只能反向爬回去,
     * 对于每只蚂蚁,他们都知道距离左端的距离xi,但是不知道它当前的方向,计算蚂蚁落下竿子的最长时间和最短时间。
     * @author Administrator
     *
     */
    public class Main3 {
    
    	
    	private static final int C = 100;
    	public static void main(String[] args) {
    		Scanner input = new Scanner(System.in);
    		int L = input.nextInt();
    		int n = input.nextInt();
    		int x[] = new int[n];
    		for (int i=0;i<x.length;i++) {
    			x[i] = input.nextInt();
    		}
    		int minT = 0;
    		int maxT = 0;
    		for (int i=0;i<n;i++) {
    			minT = Math.max(minT, Math.min(x[i], L-x[i]));
    		}
    		for (int i=0;i<n;i++) {
    			maxT = Math.max(maxT, Math.max(x[i], L-x[i]));
    		}
    		
    		
    		System.out.println(minT+"	"+maxT);
    		
    	}
    	
    }
    

      

  • 相关阅读:
    解决死锁四大方式
    Windows内存管理简介:
    排序算法优劣
    排序
    HTTPs
    http和https的异同
    HTTP协议
    FTP与TFTP
    tomcat热部署
    开发心得体会
  • 原文地址:https://www.cnblogs.com/airycode/p/4834995.html
Copyright © 2011-2022 走看看