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 ...
随机推荐
- C++输出字符指针指向的地址
int main() { char *s2 = "jwdajkj"; ]; )); printf("%p,%p\n", s3, s1); cout <&l ...
- Scala操作外部数据
Scala操作外部数据: 1.操作文件 2.操作XML 3.操作MySQL 读取文件: object FileApp { def main(args: Array[String]): Unit = { ...
- Scala面向对象
面向对象编程OOP: Scala vs Java 都有这三特性 封装:把属性.方法封装到类中 Person: int id, String name, Date birthday.... 需要gett ...
- Linux部署禅道环境
1.打开WinSCP 2. 输入Linux IP 用户名(root)及密码(123456)并点击保存 3. 点击登录后再输入一次密码 4.把ZenTaoPMS.11.2.stable.zbox_6 ...
- ubuntu下mysql定时备份
一:ubuntu下自动备份mysql数据库 转载来源:https://jingyan.baidu.com/article/ab0b563097cabac15afa7dbc.html 1.创建保存备份文 ...
- [CodeForces 52C]Circular RMQ
题目传送门 评分:省选/NOI-,难度:普及+/提高 这题真的和RMQ没有半点关系,只需要一个裸的线段树,连pushdown都不需要,只需要两种操作:区间修改和区间求最小值,在回溯时加上标记即可,唯一 ...
- angularjs 信息链接 转摘自:http://www.zhihu.com/question/27427447
这个问题嘛,真不好回答,问的太笼统了,其实你只要熟悉掌握了Angular.js,自然而然的就会用Angular.js结合自身的业务去构建SPA程序了,Angular.js是一个比较全面的框架,按照他的 ...
- SharePoint创建web应用程序,提示密码不正确
使用版本SharePoint2010: $username="domain\username"$newpassword="xxxxxxxx"stsadm -o ...
- 关于手机端在同一个Grid中使用不同的布局展现即Layout的使用
标题可能说的不是很清楚,我举个栗子好了,现在你正在写手机端的一个审批模块,这个模块要求能够展示所有待审批的信息 比如出差申请,请假申请,加班申请,以及报销申请 那么我的思路有两个 1:建立一个Tab页 ...
- BZOJ3625 CF438E 小朋友与二叉树
心态崩了 不放传送门了 辣鸡bz 还是正经一点写一下题解= = 就是显然我们可以把权值写成生成函数形式g(0/1序列)来表示权值是否出现 然后f来表示总的方案数 可以列出 分别枚举左右子树和空树的情况 ...