hdoj 5200 Trees 【思维】
来源:互联网 发布:软件售后前途 编辑:程序博客网 时间:2024/04/25 07:35
题目链接:hdoj 5200 Trees
题意:给你
块的定义:
一、临近的树在同一个块;
二、若
思路:我们先按高度升序
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#include <stack>#define PI acos(-1.0)#define CLR(a, b) memset(a, (b), sizeof(a))#define fi first#define se second#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 5*1e4+10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;void getmax(int &a, int b) {a = max(a, b); }void getmin(int &a, int b) {a = min(a, b); }void add(LL &x, LL y) { x += y; x %= MOD; }bool cmp(pii a, pii b) { return a.fi != b.fi ? a.fi < b.fi : a.se < b.se;}pii a[MAXN];bool cut[MAXN];int ans[MAXN];int main(){ int N, Q; while(scanf("%d%d", &N, &Q) != EOF) { for(int i = 0; i < N; i++) { scanf("%d", &a[i].fi); a[i].se = i; cut[i] = false; } sort(a, a+N, cmp); int cnt = 1; for(int i = 0; i < N; i++) { int id = a[i].se; int cutnum; if(id == 0) { if(cut[id+1]) { cnt--; } else { //cnt++; } } else if(id == N-1) { if(cut[id-1]) { cnt--; } else { //cnt++; } } else { if(cut[id+1] && cut[id-1]) { cnt--; } else if(!cut[id-1] && !cut[id+1]) { cnt++; } } cut[id] = true; ans[id] = cnt; //cout << id << " " << ans[id] << endl; } while(Q--) { int v; scanf("%d", &v); int p = lower_bound(a, a+N, pii(v+1, -1)) - a; if(p == 0) cout << 1 << endl; else { int id = a[p-1].se; cout << ans[id] << endl; } } } return 0;}
0 0
- hdoj 5200 Trees 【思维】
- HDU 5200 - Trees (离线 + 思维)
- 【模拟+思维】hdu5200 Trees
- HDOJ 2841 Visible Trees
- hdu 5200 Trees 排序+思维? ★★☆
- 思维树(Mind Trees)
- hdoj-1131-Count the Trees
- hdoj 1131 Count the Trees
- hdoj-1130-How Many Trees
- hdoj 5100 Chessboard 【思维】
- hdoj 5587 Array 【思维】
- hdoj 5480 Conturbatio 【思维】
- hdoj 5671 Matrix 【思维】
- hdoj 5480 Conturbatio (思维)
- hdu5200 Trees(逆向思维+离线处理)
- hdu/hdoj 1130 How Many Trees?
- HDOJ 4010 Query on The Trees LCT
- HDOJ 2215 Maple trees 最小圆覆盖
- PHP修改指定目录下的文件名
- 利用指针输出二维数组内容
- 一步一步开发安卓应用 自定义Activity标题栏
- MySQL集群
- 单向链表
- hdoj 5200 Trees 【思维】
- 第三周项目4:穷举法解决组合问题---换分币
- UIButton
- linux centos 常用命令
- java设计模式——结构型之组合模式
- 第一次作业-2
- wrk中描述进程VAD的AVL树
- 第2周项目3:小试循环(1)
- 工厂设计模式--确定对话框