Problem F: The Nearest Same Chocolate
2016-05-14 16:47
211 查看
Problem F: The Nearest Same Chocolate
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 271 Solved: 151
[Submit][Status][Web
Board]
Description
Now it is well-known that after the 40th ACM/ICPC, Diao Yang has found many girlfriends, and Diao Yang will buy much candies for them every day. But today, Diao Yang has no much money to buy any candies for his girlfriends. Because Diao Yangis always very nice to his girlfriends, these pretty girls decided to buy some chocolates for him today as return.
Then Girls went to a supermarket and chose many different chocolates. In order to distinguish these chocolates, they marked them by numbers. Any two chocolates chosen by the same girl were marked by the same number, and any two chocolates chosen by different
girls were marked by different numbers. Then girls went back home, put their chocolates in a line on the table and gave Diao Yang to eat. But before Diao Yang ate, the girls gave him a problem: can you find the distance of the nearest two chocolates which
were marked by the same girl? As Diao Yang is too hungry to solve this problem, he asks you for help.
Input
The first line contains an integer T indicating the total number of test cases.In each test case, there are two lines. The first line is an integer n(
), indicating there are chocolates. The second line contains n integers,
indicating the marked number for each chocolate. All the integers will be no more than 100.
Output
For each test case, output the answer in one line. You can assume that there are at least two chocolates which were marked by the same girl.Sample Input
282 3 8 1 5 3 4 562 3 2 1 3 1
Sample Output
32
HINT
#include<stdio.h> #include<string.h> int inf=9999999; int main() { int pos[205]; int dis[205]; int a[205]; int T; scanf("%d",&T); while(T--) { int min=inf; int n; scanf("%d",&n); for(int i=1;i<=205;i++) { pos[i]=-1; dis[i]=inf; } for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { if(pos[a[i]]==-1) pos[a[i]]=i; else { int t; t=i-pos[a[i]]; pos[a[i]]=i; if(t<dis[a[i]]) dis[a[i]]=t; } } for(int i=1;i<=n;i++) if(min>dis[i]) min=dis[i]; printf("%d\n",min); } return 0; }
相关文章推荐
- DLL的简单实现及调用
- java核心数据结构(一)——List类族
- GNU C中x++是原子操作吗?
- 汽车美容管理系统质量属性
- 文章标题
- 初学矩阵乘法—斐波拉契数列
- mysql root用户看不到mysql库下的所有表
- uva 4260 - Fortune Card Game 【dp】
- Android开发最佳实践---Futurice之见
- HDU 1171(背包)
- [未完整]谈js中的作用域链和闭包
- Toolbar总结
- Matlab中regionprops的使用示例
- 网络数据加密, 数据安全
- Codeforces 667C Reberland Linguistics 【dp】
- Linux内核将要支持最新龙芯3A2000/3B2000
- 今天犯了一个非常low的错误❌。关于UINavigationController 和UITabBarController
- mysql监控器
- Linux操作系统安装nginxs
- css3入门篇