首页 > 编程语言 > 详细

Ants-穷举算法

时间:2015-09-24 14:34:21      阅读:217      评论:0      收藏:0      [点我收藏+]
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+"\t"+maxT);
		
	}
	
}

  

Ants-穷举算法

原文:http://www.cnblogs.com/airycode/p/4834995.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!