原题链接 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. java注解编程@since 1.8

    一.基本元注解: @Retention: 说明这个注解的生命周期 RetentionPolicy.SOURCE -> 保留在原码阶段,编译时忽略 RetentionPolicy.CLASS -& ...

  2. Waiter.js

    var Waiter = function() {     var dfd = [],         doneArr = [],         failArr = [],         slic ...

  3. spring security简单教程以及实现完全前后端分离

    spring security是spring家族的一个安全框架,入门简单.对比shiro,它自带登录页面,自动完成登录操作.权限过滤时支持http方法过滤. 在新手入门使用时,只需要简单的配置,即可实 ...

  4. Struts2之动态方法调用

    1.感叹号 前台页面 <%@ page language="java" contentType="text/html; charset=UTF-8" pa ...

  5. 最短路 dijkstra算法

    题目 给定n个点的带权有向图,求从1到n的路径中边权之和最小的路径. dijkstra实现方法 用dist[i]表示i这个点到原点的最短距离,一开始初始化为无穷大,然后将原点设为0. 用ok[i]表示 ...

  6. LTP安装方法

    git clone https://github.com/linux-test-project/ltp.git apt-get install automake make autotools ./co ...

  7. python学习第十七天字符串的创建和操作方法

    字符串也是任何编程语言最常见的编程语言,字符串是有序的,可以通过下标来访问,可以切片,可以查找,可以替换,字符串可以和列表之间互相转换 join() split() 等函数 1,字符串的创建 单引号 ...

  8. linux上执行jmeter脚本

    1.linux上安装jmeter 将windows上的zip包直接放到linux上 进入bin目录,chmod 777 jmeter 修改环境变量: 1 2 3 4 # vim /etc/profil ...

  9. 攻防世界--re2-cpp-is-awesome

    测试文件:https://adworld.xctf.org.cn/media/task/attachments/c5802869b8a24033b4a80783a67c858b 1.准备 获取信息 6 ...

  10. LeetCode 852. Peak Index in a Mountain Array(C++)

    Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists som ...