原题链接 https://odzkskevi.qnssl.com/1110bec98ca57b5ce6aec79b210d2849?v=1491063604

**********************************************************************************************************************

题意:选择v[i]里的两个数相减的绝对值小于32,问你有多少对这样的数

解题思路:看题目就知道暴力枚举肯定会超时XD;

     所以就标记一下v[i],每一次找v[i]前后31个数,看看有多少个, 减去重复的,就是答案。

**********************************************************************************************************************

 #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = +;
int num[maxn];
int a[maxn];
int sum[maxn];
int vis[maxn];
int main()
{
int T;
cin >> T;
while(T--){
memset(a, , sizeof(a));
memset(num, , sizeof(num));
memset(vis, , sizeof(vis));
int n, i, ans=;
cin >> n; for(i=;i<n;i++){
cin >> a[i];
num[a[i]]++;
}
sum[]=;
for(i=;i<maxn;i++)//通过前缀和的方法求出有多少个符合
sum[i]=sum[i-]+num[i];
// for(i=1;i< 150 ;i++)
// cout << i << " " << sum[i] << endl;
for(i=;i<n;i++){
int x = a[i];
int rightn=min(, x+);//只往右边跑,避免左右一起跑出现重复
if(!vis[x]){
ans+=num[x] * (sum[rightn] - sum[x]);//加上[x,x+31]的数的个数
ans+=num[x]*(num[x]-)/;//如果同一个数出现了多次,C(2, n)个
vis[x]=;
}
}
cout << ans << endl;
}
return ;
}

Gym-100676E Time Limit Exceeded?的更多相关文章

  1. java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得

    我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...

  2. Spark java.lang.outofmemoryerror gc overhead limit exceeded 与 spark OOM:java heap space 解决方法

    引用自:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246 ...

  3. Unable to execute dex: GC overhead limit exceeded

    Android打包时下面的错误: Unable to execute dex: GC overhead limit exceeded GC overhead limit exceeded 解决的方法: ...

  4. [转]java.lang.OutOfMemoryError:GC overhead limit exceeded

    我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...

  5. android Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded

    Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded 解决方法: 找到Eclipse安装目录的文件,\eclipse\e ...

  6. android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded

    android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded 在app下的build.gradle中找到and ...

  7. GC overhead limit exceeded填坑心得

    我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...

  8. fix eclipse gc overhead limit exceeded in mac

    fix eclipse gc overhead limit exceeded: 在mac上找不到eclipse.ini文件编辑内存限制,在eclipse安装目录右击eclipse程序,选“显示包内容” ...

  9. gc overhead limit exceeded

    eclipse-- gc overhead limit exceeded 修改内存不足的方法如下: Eclipse报错:gc overhead limit exceeded eclipse 原因是Ec ...

  10. GC overhead limit exceeded解决

    java.lang.OutOfMemoryError: GC overhead limit exceeded解决   一.异常如下:Exception in thread "main&quo ...

随机推荐

  1. 【SD系列】SAP 跨年时更改销售凭证号码段

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[SD系列]SAP 跨年时更改销售凭证号码段   ...

  2. 模拟赛T5 : domino ——深搜+剪枝+位运算优化

    这道题涉及的知识点有点多... 所以还是比较有意思的. domino 描述 迈克生日那天收到一张 N*N 的表格(1 ≤ N ≤ 2000),每个格子里有一个非 负整数(整数范围 0~1000),迈克 ...

  3. 在Lua中进行运算符重载

    在C++里面运算符是可以重载的,这一点也是C++比较方便的一个地方.在Lua中其实也是可以模拟出运算符的重载的. 在Lua中table中元素的运算都是和一个叫做元表有关的,在一个table型的变量上都 ...

  4. js实现方块弹珠游戏

    下载地址:https://files.cnblogs.com/files/liumaowu/%E5%BC%B9%E4%B8%80%E5%BC%B9%E6%89%93%E6%96%B9%E5%9D%97 ...

  5. 图标,空格,大小尖括号,段落,换行,标题,div白板,span白板

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 攻防世界--open-source

    1.打开源码 打开源码 #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { ) ...

  7. Css3-文字

    一.text-overflow   text-overflow用来设置是否使用一个省略标记(...)标示对象内文本的溢出. 语法:text-overflow:clip(默认属性,表示剪切) | ell ...

  8. Intellij 选择profile

    注意有3个地方需要改

  9. React(4) --引入图片及循环数据

    引入图片的方法 1.引入本地图片 方法1: import logo from '../assets/images/1.jpg'; <img src={logo} /> 方法2: <i ...

  10. go语言从例子开始之Example32.打点器

    定时器 是当你想要在未来某一刻执行一次时使用的 - 打点器 则是当你想要在固定的时间间隔重复执行准备的.这里是一个打点器的例子,它将定时的执行,直到我们将它停止. Example: package m ...