【HDU】5247-找连续数(直接暴力)
2016-03-27 19:04
176 查看
ORZ,这道题想复杂了,原来直接暴力就能够了复杂度为 n * n * logn
#include<cstdio> #include<set> #include<algorithm> using namespace std; typedef long long LL; const int maxn = 10005; set<LL>s; set<LL>::iterator it1,it2; int n,m; int num[maxn] = {0}; LL arr[maxn]; int main(){ scanf("%d%d",&n,&m); for(int i = 0; i < n; i++) scanf("%I64d",&arr[i]); for(int i = 0; i < n; i++){ s.clear(); s.insert(arr[i]); num[1] ++; for(int j = i + 1; j < n; j++){ if(!s.count(arr[j])) s.insert(arr[j]); else break; it1 = s.begin(); it2 = s.end(); it2 --; LL e1 = *it1,e2 = *it2; if(e2 - e1 == s.size() - 1){ //printf("%I64d %I64d\n",e1,e2); num[s.size()] ++; } } } printf("Case #1:\n"); while(m--){ int k; scanf("%d",&k); printf("%d\n",num[k]); } return 0; }
相关文章推荐
- 对象的深度克隆
- Linux服务器维护常用命令
- Qt 简单爬虫开发
- hdu4323magic number【编辑距离dp】
- 1011. A+B和C (15)
- LCD屏参数及应用举例
- Keil 保护视力背景颜色设置
- matlab 轻松绘制出曲线的动画效果
- selenium+phantomJS爬虫,适用于登陆限制强,点触验证码等一些场景
- 物联网MQTT协议分析和开源Mosquitto部署验证
- PHP中Trait特性
- 如何优雅的在 Microsoft word中插入代码
- Leetcode数组类题目
- Activity的生命周期
- 数值的整数次方
- Android-GridView的使用
- 62. Unique Paths
- MATLAB读入视频出错的解决方法
- matlab读取xml文件
- 第四周学习进度情况