题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1100

给你n个数,数的范围是1~1000,给你q个询问,每个询问问你l到r之间数的最小差是多少。

要是l到r的数字个数大于1000,必定会有两个数字重复,所以此时最小差就为0。要是小于等于1000就直接暴力即可。

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
const int N = 1e5 + ;
int a[N], cnt[]; int main()
{
int t, n, q, l, r;
scanf("%d", &t);
for(int ca = ; ca <= t; ++ca) {
scanf("%d %d", &n, &q);
for(int i = ; i < n; ++i) {
scanf("%d", a + i);
}
printf("Case %d:\n", ca);
while(q--) {
scanf("%d %d", &l, &r);
if(r - l + > ) {
printf("%d\n", );
} else {
for(int i = l; i <= r; ++i) {
++cnt[a[i]];
}
int ans = , lpos = -;
for(int i = ; i <= ; ++i) {
if(cnt[i] > ) {
ans = ;
break;
} else if(cnt[i]) {
ans = min(ans, i - lpos);
lpos = i;
}
}
for(int i = l; i <= r; ++i) {
cnt[a[i]] = ;
}
printf("%d\n", ans);
}
}
}
return ;
}

Light oj 1100 - Again Array Queries (鸽巢原理+暴力)的更多相关文章

  1. light oj 1100 - Again Array Queries(暴力,鸽巢原理)

    http://lightoj.com/volume_showproblem.php?problem=1100 刚一看到这题,要询问这么多次,线段树吧,想多了哈哈,根本没法用线段树做. 然后看看数据范围 ...

  2. Find the duplicate Number (鸽巢原理) leetcode java

    问题描述: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive ...

  3. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  4. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  5. cf319.B. Modulo Sum(dp && 鸽巢原理 && 同余模)

    B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. poj 2356 Find a multiple(鸽巢原理)

    Description The input contains N natural (i.e. positive integer) numbers ( N <= ). Each of that n ...

  7. poj2356 Find a multiple(抽屉原理|鸽巢原理)

    /* 引用过来的 题意: 给出N个数,问其中是否存在M个数使其满足M个数的和是N的倍数,如果有多组解, 随意输出一组即可.若不存在,输出 0. 题解: 首先必须声明的一点是本题是一定是有解的.原理根据 ...

  8. NYOJ 417 死神来了 鸽巢原理

    死神来了 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 有一天,王小子在遨游世界时,遇到了一场自然灾害.一个人孤独的在一个岛上,没有吃的没有喝的.在他饥寒交迫将要死亡时 ...

  9. HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

随机推荐

  1. Drawable和Bitmap的区别

    Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一种存储对象比较好 ...

  2. java金额的加减乘除

    package com.wedge.edp.framework.common.util; import java.math.BigDecimal; /** * 金额的加减乘除 */ public cl ...

  3. @Repository @Resource

    Spring的注解形式:@Repository.@Service.@Controller,它们分别对应存储层Bean,业务层Bean,和展示层Bean. @Repository.@Service.@C ...

  4. 【英语】Bingo口语笔记(5) - 英式和美式英语的发音区别

  5. 【英语】Bingo口语笔记(29) - Run系列

  6. jQuery事件绑定方式(转)

    bind() 简要描述 bind()向匹配元素添加一个或多个事件处理器. 使用方式 $(selector).bind(event,data,function) event:必需项:添加到元素的一个或多 ...

  7. 配置dg出现的错误

    ORA-09925: Unable to create audit trail file Linux-x86_64 Error: 30: Read-only file system 没有创建adump ...

  8. php文件读写锁

    $file = fopen("test.txt", $fileOpenMode); flock($file, $lockMode) or die("Can't lock& ...

  9. android中的style部分属性值介绍

    转自:http://blog.sina.com.cn/s/blog_70c759fd01013phv.html Android平台定义的主题样式: android:theme="@andro ...

  10. ECSide标签属性说明之<ec:table>

    <ec:table>标签说明 ◆ 属性: tableId描述: 设置列表的唯一标识,默认为"ec",当一个页面内有多个ECSIDE列表时,必须为每个列表指定不同的tab ...