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

题意是给你n个数,q个询问,每次求出 a 到 b(从0开始)最小差值;

直接暴力就能过:

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
#define N 1010
#define INF 0xfffffff
int num[N*], cnt[N], vis[N]; int main()
{
int T, t=, n, a, b, q;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &q);
for(int i=; i<n; i++)
scanf("%d", &num[i]);
printf("Case %d:\n", t++);
while(q--)
{
memset(vis, , sizeof(vis));
scanf("%d%d", &a, &b);
int flag = , Min = INF;
for(int i=a; i<=b; i++)
{
if(vis[num[i]]==)
{
flag=;
break;
}
else
{
for(int j=a; j<i; j++)
Min = min(Min, abs(num[i]-num[j]));
vis[num[i]] = ;
}
}
if(flag == )
Min = ;
printf("%d\n", Min);
}
}
return ;
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
#define N 1010
#define INF 0xfffffff
int num[N*], cnt[N]; int main()
{
int T, t=, n, a, b, q;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &q);
for(int i=; i<n; i++)
scanf("%d", &num[i]);
printf("Case %d:\n", t++);
while(q--)
{
memset(cnt, , sizeof(cnt));
scanf("%d%d", &a, &b);
int flag = , Min = INF, pre = ;
for(int i=a; i<=b; i++)
cnt[num[i]]++;
for(int i=; i<=; i++)
{
if(flag == )break;
if(cnt[i]>=)
{
flag = ;break;
}
if(cnt[i]==)
{
if(pre == ) pre = i;
else
{
Min = min(Min, i-pre);
if(Min == )flag = ;
pre = i;
}
}
}
if(flag == )
Min = ;
printf("%d\n", Min);
}
}
return ;
}

Again Array Queries---Lightoj1100(循环暴力)的更多相关文章

  1. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  2. Light oj-1100 - Again Array Queries,又是这个题,上次那个题用的线段树,这题差点就陷坑里了,简单的抽屉原理加暴力就可以了,真是坑~~

                                                                              1100 - Again Array Queries ...

  3. lightoj Again Array Queries

    1100 - Again Array Queries   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...

  4. AC日记——Array Queries codeforces 797e

    797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...

  5. Codeforces 797E - Array Queries

    E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...

  6. Light OJ-1082 - Array Queries,线段树区间查询最大值,哈哈,水过~~

                                                                                                        ...

  7. Yet Another Array Queries Problem CodeForces - 863D (暴力/思维)

    You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — p ...

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

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

  9. Educational Codeforces Round 19 E. Array Queries(暴力)(DP)

    传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #i ...

随机推荐

  1. JS PHP MySQL 字符长度

    摘要: js的string.length 属性取的是字符串的实际长度 php的str_len()函数取的是字符串的字节长度,中文utf-8占3个字节,gb2312占2个字节 mysql中的varcha ...

  2. Cannot proceed with delivery: an existing transporter instance is currently uploading this package

    当使用Xcode的Application Loader上传spa到AppStore的过程中,如果临时中断,当你再次进行上传的过程时,就发发现如下现象: Cannot proceed with deli ...

  3. /proc/interrupts 和 /proc/stat 查看中断的情况

    在/proc文件系统下,又两个文件提供了中断的信息. /proc/interrupts 文件中列出当前系统使用的中断的情况,所以某个中断处理没有安装,是不会显示的.哪怕之前安装过,被卸载了. 从左到右 ...

  4. easy UI动态赋值

    1,首先怎么清除这个值 $('#filegrid').datagrid('loadData', { total: 0, rows: [] }); 2,清除后,通过post提交请求,怎么将新植穿进去,这 ...

  5. URLDecoder: Incomplete trailing escape (%) pattern问题处理

    http://blog.csdn.net/yangbobo1992/article/details/10076335 _________________________________________ ...

  6. div随页面滚动遇顶固定的两种方法(js&jQuery)

    一.遇顶固定的例子 我一直以为是某个div或层随屏幕滚动,遇顶则固定,离开浏览器顶部又还原这样的例子其实不少,其实它的名字叫“层的智能浮动效果”.目前我们在国内的商业网站上就常常看到这样的效果了.例如 ...

  7. Spring的一种拦截器SimpleUrlHandlerMapping

    spring的一种拦截器,用于在XML文件中配置以拦截url,它是以map映射的方式进行拦截.映射是从前台urls到具体后台的beans.同时支持到bean实例和bean名称的映射,后者要求非单实例控 ...

  8. 【BZOJ】1042: [HAOI2008]硬币购物(dp+容斥原理)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1042 一开始写了个O(nv)的背包,果断tle... 看了题解,,好神..用了组合数学中的多重集合方 ...

  9. mac zsh选择到行首的快捷键

    Mac OS X 下zsh切换窗口的快捷键:Shift-Command-←. 移动到当前命令行的行首,使用快捷键[Ctrl][A].移动到当前命令行的行尾,使用快捷键[Ctrl[E].

  10. ie中自动识别单屏与双屏(js)

    <!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...