The Nearest Same Chocolate
来源:互联网 发布:软件社群 编辑:程序博客网 时间:2024/05/17 20:30
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 Yang is 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
int main()
{
int t,n,i=0,j=0,m=0;
int min=200;
int a[105];
scanf("%d",&t);
while(t--)
{
min=200;//此处忘了,导致一直WA,当多组数据时要赋值新的新值。
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
if(a[i]==a[j])
{
m=j-i;
if(min>m)
min=m;
}
}
if(min==200)
printf("%d\n",0);
else
printf("%d\n",min);
}
return 0;
}
- The Nearest Same Chocolate
- HZAU 1006 The Nearest Same Chocolate
- Problem F: The Nearest Same Chocolate
- Reginal2011_Chengdu_B Break the Chocolate
- hdu4112: Break the Chocolate
- Break the Chocolate HDU
- The nearest taller cow
- HDU 4112 Break the Chocolate
- hdu-4112-Break the Chocolate
- hdu 4112 Break the Chocolate
- HDU - 4112 Break the Chocolate
- HDU - 4112 Break the Chocolate
- just the same和all the same
- duplicate the same db
- The same feeling
- Under The Same Sky
- The Same Dream
- POJ1027--The Same Game
- 【Scoket编程】篇二
- Mybatis分库分表扩展插件
- MYSQL忘记密码后跳过权限检查修改密码
- Python闲谈(二)聊聊最小二乘法以及leastsq函数
- java28接口的基本语法
- The Nearest Same Chocolate
- Spring+SpringMVC+MyBatis+Maven框架整合
- Reverse String(easy)
- The import javax.servlet cannot be resolved
- 浅谈android中加载高清大图及图片压缩方式(二)
- 三、友录-通话记录功能
- C#技术分享【Word转换成图片和PDF——2种方案】
- C语言中数组的分配和访问
- php压缩与归档扩展总结