原题链接 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. Bootstrap 学习笔记7 模态框插件

    网站弹出框使用: 基本使用: <!-- 模态框的声明 --> <div class="modal" id="myModal" tabindex ...

  2. Django first()和last() F查询以及Q查询

    一.first()和last() 分别返回queryset的第一项与最后一项,具体用法如下: p = Blog.objects.order_by('title').first() 等同于: try: ...

  3. “希希敬敬对”Alpha版本发布说明

    Alpha版本的所有功能如下: 1.完成根据贴吧关键字检索的功能,通过用户输入的关键词或URL地址链接到对应的贴吧页面,并爬取到该贴吧前10页的相关数据.2.对爬取到的数据进行分析和整合,实现获取该贴 ...

  4. 厉害了,Google大神每天写多少行代码?

    文章转自开源中国社区,编译自:Quora Quora上有个有趣的问题:Google工程师们每天写多少行代码? Google 的 AdMob 全栈工程师 Raymond Farias 在 Quora 发 ...

  5. LeetCode Array Easy 485. Max Consecutive Ones

    Description Given a binary array, find the maximum number of consecutive 1s in this array. Example 1 ...

  6. Ubuntu14.04(nginx+php+mysql+vsftp)配置安装流程

    Ubuntu14.04(nginx+php+mysql+vsftp)配置安装流程 1.先切换到root用户 sudo  su 2.更新软件源 apt update apt-get upgrade 3. ...

  7. 2018-2-13-C#-复制列表

    title author date CreateTime categories C# 复制列表 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23:3 +0 ...

  8. Linux ssh黄金参数

    Linux ssh黄金参数 命令: -o ConnectionAttempts= -o PasswordAuthentication=no -o StrictHostKeyChecking=no cp ...

  9. 295-Xilinx Kintex-7 X7K325T的半高PCIe x4双路万兆光纤收发卡

    Xilinx Kintex-7 X7K325T的半高PCIe x4双路万兆光纤收发卡 一.板卡概述       本板卡系我公司自主研发,采用Xilinx公司的XC7K325T-2FFG676I芯片作为 ...

  10. leetcode 001

    1 Two Sum Difficulty: Easy The Link: https://leetcode.com/problems/two-sum/description/ Description ...