题目链接: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. fixed兼容IE6

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. spring tx:advice 和 aop:config 配置事务

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. android 中解析XML的方法(转)

    在XML解析和使用原始XML资源中都涉及过对XML的解析,之前使用的是 DOM4J和 XmlResourceParser 来解析的.本文中将使用XmlPullParser来解析,分别解析不同复杂度的t ...

  4. 【英语】Bingo口语笔记(2) - 吞音

  5. marginCollapse之兄弟关系的DIV

    废话不说,直接上图 基本代码如下: 效果图如下: 给两个div分别加marginBottom和marginTop看一下效果 实际效果如下: 我们可以看出两个div之间的距离并不是50+50,而是只显示 ...

  6. c# datagridview表格控件常用操作

    1) 行右键菜单 private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { ...

  7. hdu 4927 java求组合数(大数)

    import java.util.Scanner; import java.math.BigInteger; public class Main { private static int [] a = ...

  8. hdu 1527(威佐夫博奕)

    题意:容易理解. 分析:威佐夫博奕的模板题. 代码实现: #include<stdio.h> #include<string.h> #include<math.h> ...

  9. Modularity模块化

    Modularity in this context refers to test scripts, whereas independence refers to test cases. Given ...

  10. CMDB反思5

    ITSM工具规划设计 http://blog.vsharing.com/xqscool/A946789.html 相比PPT中被管的数个对象(像培训什么的也都在其中),我们的需求其实就要小得多,但是问 ...