hdu 5200 Trees 排序+思维? ★★☆
来源:互联网 发布:笑傲江湖ol捏脸数据女 编辑:程序博客网 时间:2024/03/29 06:23
Trees
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1282 Accepted Submission(s): 398
Problem Description
Today CodeFamer is going to cut trees.There are N trees standing in a line. They are numbered from 1 to N . The tree numbered i has height hi . We say that two uncutted trees whose numbers are x and y are in the same block if and only if they are fitting in one of blow rules:
1)x+1=y or y+1=x;
2)there exists an uncutted tree which is numberedz , and x is in the same block with z , while y is also in the same block with z .
Now CodeFamer want to cut some trees whose height is not larger than some value, after those trees are cut, how many tree blocks are there?
1)x+1=y or y+1=x;
2)there exists an uncutted tree which is numbered
Now CodeFamer want to cut some trees whose height is not larger than some value, after those trees are cut, how many tree blocks are there?
Input
Multi test cases (about 15 ).
For each case, first line contains two integersN and Q separated by exactly one space, N indicates there are N trees, Q indicates there are Q queries.
In the followingN lines, there will appear h[1],h[2],h[3],…,h[N] which indicates the height of the trees.
In the followingQ lines, there will appear q[1],q[2],q[3],…,q[Q] which indicates CodeFamer’s queries.
Please process to the end of file.
[Technical Specification]
1≤N,Q≤50000
0≤h[i]≤1000000000(109)
0≤q[i]≤1000000000(109)
For each case, first line contains two integers
In the following
In the following
Please process to the end of file.
[Technical Specification]
Output
For each q[i] , output the number of tree block after CodeFamer cut the trees whose height are not larger than q[i] .
Sample Input
3 252362
Sample Output
02HintIn this test case, there are 3 trees whose heights are 5 2 3.For the query 6, if CodeFamer cuts the tree whose height is not large than 6, the height form of left trees are -1 -1 -1(-1 means this tree was cut). Thus there is 0 block.For the query 2, if CodeFamer cuts the tree whose height is not large than 2, the height form of left trees are 5 -1 3(-1 means this tree was cut). Thus there are 2 blocks.
Source
BestCoder Round #36 ($)
Recommend
hujie | We have carefully selected several similar problems for you: 5599 5598 5597 5596 5595
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<climits>#include<queue>#include<vector>#include<map>#include<sstream>#include<set>#include<stack>#include<cctype>#include<utility>#pragma comment(linker, "/STACK:102400000,102400000")#define PI (4.0*atan(1.0))#define eps 1e-10#define sqr(x) ((x)*(x))#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)#define lson ind<<1,le,mid#define rson ind<<1|1,mid+1,ri#define MID int mid=(le+ri)>>1#define zero(x)((x>0? x:-x)<1e-15)#define mk make_pair#define _f first#define _s secondusing namespace std;//const int INF= ;typedef long long ll;//const ll inf =1000000000000000;//1e15;//ifstream fin("input.txt");//ofstream fout("output.txt");//fin.close();//fout.close();//freopen("a.in","r",stdin);//freopen("a.out","w",stdout);const int INF =0x3f3f3f3f;const int maxn= 50000+20 ;//const int maxm= ; int n,q; int sum[maxn];bool vis[maxn];struct Node{ int hei,ind; }a[maxn]; bool cmp(Node x,Node y){ return x.hei>y.hei;} int search(int x){ int le=1,ri=n; while(le<=ri) { int mid=(le+ri)/2; if(a[mid].hei<=x) ri=mid-1; else le=mid+1; } return ri;}int main(){ int x; while(~scanf("%d%d",&n,&q)) { FOR1(i,n) scanf("%d",&a[i].hei),a[i].ind=i; sort(a+1,a+1+n,cmp); memset(vis,0,sizeof vis); sum[0]=0,sum[1]=1; vis[ a[1].ind ] =1; for(int i=2;i<=n;i++) { x=a[i].ind; if( (vis[x-1]&& !vis[x+1]) || (!vis[x-1]&& vis[x+1]) ) { sum[i]=sum[i-1]; } else if( vis[x-1]&&vis[x+1] ) { sum[i]=sum[i-1]-1; } else { sum[i]=sum[i-1]+1; } vis[x]=1; } /* for(int i=1;i<=n;i++) { cout<<i<<" "<<sum[i]<<endl; }*/ while(q--) { scanf("%d",&x); int p=search(x); printf("%d\n",sum[p]); } } return 0;}/*6 312 7 10 15 7 871012*/
0 0
- hdu 5200 Trees 排序+思维? ★★☆
- HDU 5200 - Trees (离线 + 思维)
- hdoj 5200 Trees 【思维】
- hdu 5200 Trees(离线处理,排序)
- HDU 5200 Trees
- hdu 5200 Trees
- [思维+容斥原理] hdu 2841 Visible Trees
- Hdu 1872 稳定排序【思维】
- HDU - 5200 - Trees (upper_bound)
- hdu 5200 trees(离线处理)
- 【模拟+思维】hdu5200 Trees
- HDU 5821 Ball (排序、思维题)
- hdu 3466 (01背包+思维排序)
- Hdu 5200 Trees (离线线段树)
- HDU 5200/BC 36 C Trees
- HDU 5200 Trees 离线+链表维护.
- 思维树(Mind Trees)
- hdu 5200 离线处理+思维
- poj2704Pascal's Travels【记忆化搜索】
- windbg分析运行在64位环境下的32位程序的dump
- What is the difference between addView and addViewInLayout?
- 网络参考模型 七层-四层
- MySQL关于timestamp和mysqldump的一个“bug”
- hdu 5200 Trees 排序+思维? ★★☆
- How To Configure Client Failover For Dataguard Connections Using Database Services (Doc ID 1429223.1
- 剑指offer第三十五题【二叉树的深度】c++实现
- android 程序崩溃捕获日志
- UITouch详解
- C++ Eigen库学习
- 前端开发-HTML5基础
- 机器人路径规划_蚁群算法
- python处理log数据