Again Array Queries---Lightoj1100(循环暴力)
题目链接: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(循环暴力)的更多相关文章
- codeforces 797 E. Array Queries【dp,暴力】
题目链接:codeforces 797 E. Array Queries 题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...
- Light oj-1100 - Again Array Queries,又是这个题,上次那个题用的线段树,这题差点就陷坑里了,简单的抽屉原理加暴力就可以了,真是坑~~
1100 - Again Array Queries ...
- lightoj Again Array Queries
1100 - Again Array Queries PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 ...
- AC日记——Array Queries codeforces 797e
797E - Array Queries 思路: 分段处理: 当k小于根号n时记忆化搜索: 否则暴力: 来,上代码: #include <cmath> #include <cstdi ...
- Codeforces 797E - Array Queries
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds m ...
- Light OJ-1082 - Array Queries,线段树区间查询最大值,哈哈,水过~~
...
- 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 ...
- light oj 1100 - Again Array Queries(暴力,鸽巢原理)
http://lightoj.com/volume_showproblem.php?problem=1100 刚一看到这题,要询问这么多次,线段树吧,想多了哈哈,根本没法用线段树做. 然后看看数据范围 ...
- 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 ...
随机推荐
- DRBD安装配置、工作原理及故障恢复
一.DRBD简介 DRBD的全称为:Distributed ReplicatedBlock Device(DRBD)分布式块设备复制,DRBD是由内核模块和相关脚本而构成,用以构建高可用性的集群.其实 ...
- php插入代码数据库
插入代码:<?php $con = mysql_connect("localhost","peter","abc123"); if ( ...
- 关于Unity的C#基础学习(二)
一.Debug的使用 int a=3; Debug.Log("a="+a); 二.整数的定义 int m; Debug.Log(m); //C#比C更严谨,没有初始化的变量打印出 ...
- 关于Unity的C#基础学习(一)
一.程序包含 1.数据:运行过程中产生的 2.代码:代码指令 数据和代码都是存放到内存中的,代码指令在程序加载的时候放到内存,数据是在程序运行的时候在内存中动态地生成,随时会被回收,要定义变量来存放数 ...
- 关于Unity5.5中2D动画的制作
1.首先要创建一个精灵 GameProject--2Dproject--Sprite 叫bird 2.给这个精灵附加纹理,并让它显示自己想让它显示的场景层中,一般它的静止纹理就是动画的第一张图片 3. ...
- GitHub 上 57 款最流行的开源深度学习项目【转】
GitHub 上 57 款最流行的开源深度学习项目[转] 2017-02-19 20:09 334人阅读 评论(0) 收藏 举报 分类: deeplearning(28) from: https:// ...
- XML 是一种元语言, 可以用它来描述其他语言。
A.正确 B.错误 解答:B XML(Extensible Markup Language)即可扩展标记语言,它与HTML一样,都是SGML(Standard Generalized Markup L ...
- virtualbox pxe启动
在设置——系统中更改启动顺序,优先使用网路启动,如果你的网络环境支持PXE启动,就可以使用网络安装了. 转自: http://blog.csdn.net/huanghuibai/article/det ...
- Ubuntu执行su后输入密码结果认证失败--解决办法:sudo passwd修改命令
- 第4章 Vim编辑器与Shell命令脚本
章节简述: 本章节将教给您如何使用Vim编辑器来编写文档.配置主机名称.网卡参数以及yum仓库 ,熟练使用各个模式和命令快捷键. 我们可以通过Vim编辑器将Linux命令放入合适的逻辑测试语句(if. ...