HDU5200 Trees (离线处理)
来源:互联网 发布:淘宝排行查询 编辑:程序博客网 时间:2024/04/28 21:47
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5200
题意:
每次去掉高度小于q的树,每次输出剩下的块数。
分析:
我们对高度从高到低进行排序,对要去掉的高度从低到高进行排序。
因此前面去掉的在后面一定会去掉,因可以离线处理,节省时间,
然后需要开一个辅助空间,记录这棵树去没有去掉。
代码如下:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <set>#include <map>using namespace std;const int maxn = 50010;int vis[maxn],ans[maxn];struct tree{ int h,id; bool operator <(const struct tree &tmp) const{ return h > tmp.h; }}p[maxn];struct query{ int h,id; bool operator <(const struct query &tmp) const{ return h<tmp.h; }}q[maxn];inline int S(){ int ret=0,ok=0; char c; while((c=getchar())) { if(c>='0'&&c<='9') ret=ret*10+c-'0',ok=1; else if(ok) return ret; } return ret;}int main(){ int n,m; while(~scanf("%d%d",&n,&m)){ for(int i=0;i<n;i++){ p[i].h=S(); p[i].id=i+1; } sort(p,p+n); for(int i=0;i<m;i++){ q[i].h=S(); q[i].id=i+1; } sort(q,q+m); int tot = 0; memset(vis,0,sizeof(vis)); for(int i = 0,j = m-1;j>=0;j--){ for(;i<n;i++){ if(p[i].h<=q[j].h) break; vis[p[i].id]=1; if(!vis[p[i].id-1]&&!vis[p[i].id+1]) tot++; else if(vis[p[i].id-1]&&vis[p[i].id+1]) tot--; } ans[q[j].id]=tot; } for(int i=0;i<m;i++) printf("%d\n",ans[i+1]); } return 0;}
0 0
- HDU5200 Trees (离线处理)
- hdu5200 Trees(逆向思维+离线处理)
- hdu5200 Trees
- hdu5200 Trees( two points)
- 【模拟+思维】hdu5200 Trees
- hdu 5200 trees(离线处理)
- HDU5200
- BestCoder Round #36(Trees-离线处理询问)
- hdu 5200 Trees(离线处理,排序)
- HDU 5200 - Trees (离线 + 思维)
- 离线处理
- Hdu 5200 Trees (离线线段树)
- HDU 5200 Trees 离线+链表维护.
- 二分(hdu5200)
- XMPP离线处理
- hdu 5139 (离线处理)
- 离线处理例题
- hdu 5139(离线处理)
- 动态规划之矩阵连乘
- 使用UIViewController自定义UITabBarController
- 在AndroidStudio下搭建AGES开发框架
- 【codeforces】 ZeptoLab Code Rush 2015 A,B,C,D,E题解
- 顺序容器
- HDU5200 Trees (离线处理)
- 第15题
- 第五周上机实践项目2——对象作为数据成员
- Linux用户态和内核态
- AndroidDemo - FloatWindowDemo
- 欢迎使用CSDN-markdown编辑器
- labview的局部变量
- 16年的长度 记录中国独立游戏
- JAVA编程思想(第4版) this关键字用法小结