HDU 5200/BC 36 C Trees
2015-09-28 21:30
260 查看
其实没有官方题解说的那么麻烦(>﹏<) 直接离线处理后 开个数组模拟下即可
砍当前树时 当左右的树被砍掉时 ans就--
都没被砍掉 ans就++
砍当前树时 当左右的树被砍掉时 ans就--
都没被砍掉 ans就++
#include<iostream> #include<cstdio> #include<cstring> #include<cctype> #include<cmath> #include<vector> #include<queue> #include<map> #include<algorithm> #include<set> #define scnaf scanf #define cahr char #define bug puts("bugbugbug"); using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; const int mod=1000000007; const int maxn=5e4+100; const int inf=1e9; inline void RDF(int &ret) { //输入为负数 char c; int sgn; while(c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while(c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0'); ret *= sgn; } inline void RD(int &ret) { //输入为整数 char c; do { c = getchar(); } while(c < '0' || c > '9'); ret = c - '0'; while((c = getchar()) >= '0' && c <= '9') { ret = ret * 10 + (c - '0'); } } inline void OT(int a) { //输出为正数 if(a >= 10) { OT(a / 10); } putchar(a % 10 + '0'); } struct T { int h,id; bool operator < (const T &b) const { return h<b.h; } }a[maxn],q[maxn]; int tree[maxn],ans[maxn]; int main() { int n,Q; while(~scanf("%d%d",&n,&Q)) { tree[0]=tree[n+1]=-1; for(int i=0;i<n;i++) { RD(a[i].h); a[i].id=i+1; tree[i+1]=1; } sort(a,a+n); for(int i=0;i<Q;i++) { RD(q[i].h); q[i].id=i; } sort(q,q+Q); int cnt=0,anss=1; for(int i=0;i<Q;i++) { while(cnt<n&&a[cnt].h<=q[i].h) { int now=a[cnt].id; tree[now]=-1; if(tree[now-1]==tree[now+1]) if(tree[now-1]==-1) anss--; else anss++; cnt++; } ans[q[i].id]=anss; } for(int i=0;i<Q;i++) { //cout<<ans[i]<<endl; OT(ans[i]);puts(""); } } }
相关文章推荐
- 基于MSP430F2618的程控电压源
- OCP-V13-040
- 适配器模式
- 【c和指针学习笔记】函数指针的初始化以及函数调用的三种方式
- POJ——1922 Ride to School
- OCP-V13-039
- UGUI制作Tab标签页
- 协方差计算方法
- ocp-v13-038
- ocp-v13-037
- 20150928所学粗略整理
- 手动实现pow(x,n)的功能--20150927
- HDU 5469(Antonidas-树上匹配字符串)
- ocp-v13-036
- 上千亿的红海市场,如何逆袭出一个新品牌?(80%产品,20%营销,群众路线)
- 沪上各区免费停车场大全
- build.gradle 的设置和相关说明
- HDU 5199/BC 36B Gunner
- 关于Glide——一个高效的图片加载和缓存类库
- [LeetCode-283] Move Zeroes(移动零元素)