A. Reconnaissance 2
2016-04-21 19:03
1371 查看
A. Reconnaissance 2time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputn soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouringsoldiers, 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.InputThe 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.OutputOutput 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 test(s)input
5 10 12 13 15 10output
5 1input
4 10 20 30 40output
1 2
/* *********************************************** Author : Created Time :2015/6/14 12:18:25 File Name :7.cpp ************************************************ */ #include <iostream> #include <cstring> #include <cstdlib> #include <stdio.h> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <iomanip> #include <list> #include <deque> #include <stack> #define ull unsigned long long #define ll long long #define mod 90001 #define INF 1<<30 #define maxn 10000+10 #define cle(a) memset(a,0,sizeof(a)) const ull inf = 1LL << 61; const double eps=1e-5; using namespace std; bool cmp(int a,int b){ return a>b; } int a[maxn]; int main() { #ifndef ONLINE_JUDGE //freopen("in.txt","r",stdin); #endif int n; int x,y; while(cin>>n){ for(int i=1;i<=n;i++) cin>>a[i]; a[n+1]=a[1]; int Min=INF; for(int i=2;i<=n+1;i++){ if(abs(a[i]-a[i-1])<Min){ Min=abs(a[i]-a[i-1]); x=i;y=i-1; if(x>n)x=1; } } cout<<y<<" "<<x<<endl; } return 0; }
相关文章推荐
- A. Reconnaissance
- HDU 1839 Delay Constrained Maximum Capacity Path
- HDU1789 Doing Homework again(贪心)
- 爬楼梯的问题Climbing Stairs
- 十、责任链模式Chain of Responsibility(行为型模式)
- http://blog.csdn.net/holybin/article/details/46955185
- 服务器端主动关闭连接, 产生的TIME_WAIT状态为什么会占用服务端大量端口?
- HoloLens开发手记-硬件细节 Hardware Detail
- git修改提交的用户名和Email
- 03-树3 Tree Traversals Again
- 服务器TIME_WAIT和CLOSE_WAIT详解和解决办法
- 正确使用Block避免Cycle Retain和Crash
- lightoj 1076 - Get the Containers 【二分 + 贪心】
- Failed to read artifact descriptor进行安装maven项目出错
- AI编辑SVG格式的相关问题
- paip.自适应网页设计 跟 响应式 设计的区别跟原理and实践总结
- 图解RAID 0, RAID 1, RAID 5, RAID 10
- go gomail
- R语言中的正则表达式(转载:http://blog.csdn.net/duqi_yc/article/details/9817243)
- kaidi中 install cuda