Gym-100676E Time Limit Exceeded?
原题链接 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?的更多相关文章
- java.lang.OutOfMemoryError:GC overhead limit exceeded填坑心得
我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...
- Spark java.lang.outofmemoryerror gc overhead limit exceeded 与 spark OOM:java heap space 解决方法
引用自:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246 ...
- Unable to execute dex: GC overhead limit exceeded
Android打包时下面的错误: Unable to execute dex: GC overhead limit exceeded GC overhead limit exceeded 解决的方法: ...
- [转]java.lang.OutOfMemoryError:GC overhead limit exceeded
我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...
- android Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded
Eclipse执行项目提示错误: unable to execute dex: GC orerhead limit exceeded 解决方法: 找到Eclipse安装目录的文件,\eclipse\e ...
- android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
android studio Error:java.lang.OutOfMemoryError: GC overhead limit exceeded 在app下的build.gradle中找到and ...
- GC overhead limit exceeded填坑心得
我遇到这样的问题,本地部署时抛出异常java.lang.OutOfMemoryError:GC overhead limit exceeded导致服务起不来,查看日志发现加载了太多资源到内存,本地的性 ...
- fix eclipse gc overhead limit exceeded in mac
fix eclipse gc overhead limit exceeded: 在mac上找不到eclipse.ini文件编辑内存限制,在eclipse安装目录右击eclipse程序,选“显示包内容” ...
- gc overhead limit exceeded
eclipse-- gc overhead limit exceeded 修改内存不足的方法如下: Eclipse报错:gc overhead limit exceeded eclipse 原因是Ec ...
- GC overhead limit exceeded解决
java.lang.OutOfMemoryError: GC overhead limit exceeded解决 一.异常如下:Exception in thread "main&quo ...
随机推荐
- Markov Decision Process in Detail
From the last post about MDP, we know the environment consists of 5 basic elements: S:State Space of ...
- Win10.设置(放大)
1.ZC:我从感觉,我在Win10 里面截图 貌似被放大了,尤其是 在往cnblogs里面贴图的时候 比较明显,于是 度娘“Win10 自动放大”,找到如下帖子,里面有 2种设置方式: win10系 ...
- 爬虫之requests 请求
1.发送不同的请求 import requests r = requests.get('https://www.baidu.com/') r = requests.post('http://httpb ...
- Maven系列学习(二)Maven使用入门
Maven使用入门 通过上一节的学习,我们已经了解和配置好了Maven,接下来需要编写代码了 1.POM(Project Object Model,项目对象模型) 和Make的Makefile类似,M ...
- 去JQUERY化
时间 2016-05-17 12:43:59 OurJS 原文 http://ourjs.com/detail/573a9cec88feaf2d031d24fc 主题 jQuery 这是一篇使用原 ...
- 最小生成树基础算法(Prim + Krustal)
最小生成树问题的引入: 对于一个无向图G(V, E),需要用图中的n - 1条边连接图中的n个顶点并且不产生回路所产生的树就叫做生成树,其中权值总和最小的就是最小生成树. 如何求解最小生成树问题: 譬 ...
- css画百分比圆环
html: <div class="circle"> <div class="percent-circle percent-circle-left&qu ...
- git stash 后"本地代码不见了"
git stash 当本地代码不想提交覆盖,又忙于其他分支,可以先储存起来. git stash命令的作用就是将目前还不想提交的但是已经修改的内容进行保存至堆栈中,后续可以在某个分支上恢复出堆栈中的内 ...
- Linux之systemd服务配置及自动重启
layout: post title: Linux之systemd服务配置及自动重启 date: 2019-09-09 tags: linux --- Linux之systemd服务配置及自动重启 0 ...
- JavaFX程序初次运行创建数据库并执行建表SQL
在我的第一个JavaFX程序完成安装的时候才突然发现,不能要用这个软件还要手动执行Sql来建表吧? 于是我的想法是在Main程序中执行时检测数据库连接状况,如果没有检测到数据库或者连接异常,那么出现错 ...