博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P4269 [USACO18FEB]Snow Boots G
阅读量:6981 次
发布时间:2019-06-27

本文共 1852 字,大约阅读时间需要 6 分钟。

思维题。
以地板为序构造链表,再排序,然后删除走不过去的地面。
删除的时候顺便维护最大的跨度,以此判断可行性。
总的来说利用了答案的单调性。

#include 
#include
#include
#include
using namespace std;const int MAXN = 1e5 + 20;inline int read(){ int x = 0; char ch = getchar(); bool f = false; while(!isdigit(ch)) f |= (ch == '-'), ch = getchar(); while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f ? -x : x;}int N, B;struct Node{ int val; Node *pre, *nxt;}node[MAXN];struct boot{ int dep, dis, idx, ans; inline bool operator >(const boot &rhs) const { return dep > rhs.dep; } inline bool operator <(const boot &rhs) const { return idx < rhs.idx; }}b[MAXN];struct Floor{ int dep, idx; Node *pos; inline bool operator >(const Floor &rhs) const { return dep > rhs.dep; } inline bool operator <(const Floor &rhs) const { return idx < rhs.idx; }}f[MAXN];void build(){ f[1].pos = &node[1]; node[1].val = 1; for(int i = 2; i <= N; i++){ node[i].pre = &node[i - 1], node[i - 1].nxt = &node[i]; node[i].val = 1, f[i].pos = &node[i]; }}int main(){ cin>>N>>B; for(int i = 1; i <= N; i++) f[i] = (Floor){read(), i}; for(int i = 1; i <= B; i++) b[i].dep = read(), b[i].dis = read(), b[i].idx = i; build(); sort(f + 1, f + N + 1, greater
()); sort(b + 1, b + B + 1, greater
()); int p = 1, maxs = 1; for(int i = 1; i <= B; i++){ while(p <= N && f[p].dep > b[i].dep) { Node *cur = f[p].pos; cur->pre->nxt = cur->nxt; cur->nxt->pre = cur->pre; maxs = max(maxs, cur->pre->val += cur->val); ++p; } if(maxs > b[i].dis) b[i].ans = 0; else b[i].ans = 1; } sort(b + 1, b + B + 1); for(int i = 1; i <= B; i++) printf("%d\n", b[i].ans); return 0;}

转载于:https://www.cnblogs.com/wsmrxc/p/9439965.html

你可能感兴趣的文章
10_css选择符类型1.html
查看>>
修改 liteide 的 godoc 文档样式
查看>>
Java学习笔记(35)——Java集合07之TreeMap
查看>>
甲骨文推Oracle WebLogic应用服务器12c
查看>>
WEB服务器、应用程序服务器、HTTP服务器区别
查看>>
工厂方法
查看>>
IPSEC ××× 综合应用
查看>>
Linux下安装及管理应用程序
查看>>
Vmware vCenter 配置分布式交换机
查看>>
Ubuntu下RabbitVCS的安装和简单使用
查看>>
scan-tcedit-user.bat
查看>>
生活感悟(1)
查看>>
redis与mysql数据同步
查看>>
js获取url传递参数
查看>>
TF-IDF原理及使用
查看>>
jQuery中bind方法与live方法区别
查看>>
Android TCP/IP Socket Test
查看>>
分布式锁方案论证与实现
查看>>
海外邮件屡屡退信,使用海外邮件中继势不可挡
查看>>
百度 Ueditor 编辑器学习笔记
查看>>