文件名称:Soldiers
-
所属分类:
- 标签属性:
- 上传时间:2013-03-16
-
文件大小:1.12mb
-
已下载:0次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
【问题描述】
在一个划分成网格的操场上,n个士兵散乱地站在网格点上。网格点由整数坐标(x,y)表示。士兵们可以沿网格边上、下、左、右移动一步,但在同一时刻任一网格点上只能有一名士兵。按照军官的命令,士兵们要整齐地列成一个水平队列,即排列成(x,y),(x+1,y),…,(x+n-1,y)。如何选择x 和y的值才能使士兵们以最少的总移动步数排成一列。
【算法设计】
计算使所有士兵排成一行需要的最少移动步数。
【数据输入】
由文件input.txt 提供输入数据。文件的第1 行是士兵数n,1≤n≤10000。接下来n 行是士兵的初始位置,每行2 个整数x和y,-10000≤x,y≤10000。
【结果输出】
将计算结果输出到文件output.txt 中。文件的第1行中的数是士兵排成一行需要的最少移动步数。
输入文件示例 输出文件示例
input.txt output.txt
5 8-SOLDIERS
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Descr iption
N soldiers of the land Gridland are randomly scattered around the country. A position in Gridland is given by a pair (x,y) of integer coordinates. Soldiers can move- in one move, one soldier can go one unit up, down, left or right (hence, he can change either his x or his y coordinate by 1 or-1). The soldiers want to get into a horizontal line next to each other (so that their final positions are (x,y), (x+1,y), ..., (x+N-1,y), for some x and y). Integers x and y, as well as the final order of soldiers along the horizontal line is arbitrary. The goal is to minimise the total number of moves of all the soldiers that takes them into such configuration. Two or more soldiers must never occupy the same position at the same time.
Input
The first line of the input contains the integer N, 1 <= N <= 10000, the number of soldiers. The following N lines of the input conta
(系统自动生成,下载前可以参看下载内容)
下载文件列表
Soldiers/
Soldiers/Debug/
Soldiers/Debug/Soldiers.exe
Soldiers/Debug/Soldiers.ilk
Soldiers/Debug/Soldiers.obj
Soldiers/Debug/Soldiers.pch
Soldiers/Debug/Soldiers.pdb
Soldiers/Debug/vc60.idb
Soldiers/Debug/vc60.pdb
Soldiers/Soldiers.cpp
Soldiers/Soldiers.dsp
Soldiers/Soldiers.dsw
Soldiers/Soldiers.ncb
Soldiers/Soldiers.opt
Soldiers/Soldiers.plg
Soldiers/Soldiers思路.txt
Soldiers/题目.txt
Soldiers/Debug/
Soldiers/Debug/Soldiers.exe
Soldiers/Debug/Soldiers.ilk
Soldiers/Debug/Soldiers.obj
Soldiers/Debug/Soldiers.pch
Soldiers/Debug/Soldiers.pdb
Soldiers/Debug/vc60.idb
Soldiers/Debug/vc60.pdb
Soldiers/Soldiers.cpp
Soldiers/Soldiers.dsp
Soldiers/Soldiers.dsw
Soldiers/Soldiers.ncb
Soldiers/Soldiers.opt
Soldiers/Soldiers.plg
Soldiers/Soldiers思路.txt
Soldiers/题目.txt
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.