Reconnaissance 2(水题)
来源:互联网 发布:云视通摄像头扫描软件 编辑:程序博客网 时间:2024/06/02 02:38
Description
n soldiers stand in a circle. For each soldier his heightai is known. A reconnaissance unit can be made of such twoneighbouring soldiers, whose heights difference is minimal, i.e.|ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input
The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle —n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction.
Output
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Sample Input
510 12 13 15 10
5 1
410 20 30 40
1 2
题意:n个士兵站成一个圈,求相邻差值最小的两个士兵的位置。
ps:因为数据很小,所以可以直接遍历,但是要注意手尾要单独计算
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#define inf 999999int a[1010];int main(){ int n,i,j; int min; while(~scanf("%d",&n)) { min=inf; scanf("%d",&a[1]); for(i=2;i<=n;i++) { scanf("%d",&a[i]); if(fabs(a[i]-a[i-1])<min) { min=fabs(a[i]-a[i-1]); j=i;//j记录位置; } } if(fabs(a[n]-a[1])<min)//首尾的单独计算 printf("%d 1\n",n); else printf("%d %d\n",j-1,j); } return 0;}
- Reconnaissance 2(水题)
- A. Reconnaissance 2
- A. Reconnaissance 2
- Reconnaissance
- CodeForces 34A Reconnaissance 2
- CODEFORCES, 34A,Reconnaissance 2
- A - Reconnaissance 2 士兵 立正啦…
- 【水数组】#34 A. Reconnaissance 2
- Codeforce 34A-Reconnaissance 2(水)
- A. Reconnaissance
- Review: SANS SEC550 Information Reconnaissance
- 【水排序】#32 A. Reconnaissance
- Directory traversal as a reconnaissance tool
- Testing: Conduct search engine discovery/reconnaissance for information leakage (OTG-INFO-001)
- hdu 1716 排列2(水题)
- 小天使改名(水题 杭电排位赛-2)
- 水题2
- Codeforces Round #277 (Div. 2) A (水题)B(水题) C(贪心)
- android获取状态栏高度
- 使用fusioncharts实时数据库来生成报表,描述趋势
- 3.1 Maximum likelihood and least square
- DECODE函数实现列转行
- Java管道 PipedInputStream PipedOutputStream
- Reconnaissance 2(水题)
- JAVA面试常见编程题总结
- RID、DR、BDR以及广播多路访问、非广播多路访问实验
- ios 通过调用系统摄像头拍照,拍视频,然后写入文件
- RadioGroup 的分列换行
- FrameSize、WinSize、VisibleSize、VisibleOrigin概念理解
- hdu4607:Park Visit
- TIOBE 2014年11月编程语言排行榜 R跃升至12位
- 利用Android Lost通过互联网或短信远程控制安卓设备