P4269 [USACO18FEB]Snow Boots G
思维题。
以地板为序构造链表,再排序,然后删除走不过去的地面。
删除的时候顺便维护最大的跨度,以此判断可行性。
总的来说利用了答案的单调性。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
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<Floor>());sort(b + 1, b + B + 1, greater<boot>());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
P4269 [USACO18FEB]Snow Boots G相关推荐
- 2019 GDUT Rating Contest II : Problem G. Snow Boots
题面: G. Snow Boots Input file: standard input Output file: standard output Time limit: 1 second Memory ...
- Snow Boots
传送门 题面: Snow Boots time limit per test:1 second memory limit per test:256 megabytes inputstandard:in ...
- python init main_python 模块中的 __init__.py __main__.py
python中文件夹想作为一个模块被引用,则在文件夹内必须要包含 __init__.py 文件,即使此文件为空. 如果此模块想要运行则必须要包含 __main__.py 文件.接下来说下两个文件起到的 ...
- GDUT 寒假排位赛二
直接看题 [题目链接]: http://codeforces.com/group/NVaJtLaLjS/contest/238204 A. Taming the Herd(签到题) 题意: 有一张表, ...
- 在Asp.net页面中实现数据饼图
ASP.NET之所以能够在客户端浏览器中形成各种数据图片,是因为在ASP.NET中提供了绘图功能,具体的作法是先在服务器端创建一个Bitmap实例,然后利用ASP.NET中提供的绘图功能,按照要生成的 ...
- php输出mysql查询结果_PHP简单获取数据库查询结果并返回JSON
header("Content-type:text/html;charset=utf-8"); //连接数据库 $con = mysql_connect("localho ...
- JAVA范例 十三)多线程编程(3)
线程应用实例 实例244 下雪的村庄 package Chapter17;import java.applet.Applet; import java.awt.*; import java.util. ...
- janusgraph 引入 java_JanusGraph入门第一课和官方文档踩坑
入门第一课是在IDEA里创建一个项目,有些小曲折.这里运行的Demo是读取janusgraph示例的"神之图"(Graph of the Gods)数据并打印,采用Hbase+ES ...
- 用关键字搜索lazada商品详情
目前店铺订单和店铺商品接口权限已经不支持申请应用,有好多做店群业务,店铺订单同步,店铺交易,店铺订单物流,店铺订单消息推送,店铺订单插旗,店铺上传商品,店铺修改商品属性,店铺上货等操作均不能操作了,使 ...
最新文章
- life at University of Liverpool
- 30+个必知的《人工智能》会议清单
- Ubuntu 系统安装APACHE PHP MYSQL
- linux tcl expect 安装(转)
- Think in Java ---Chapter 8 多态 [基础的混凝土大厦]
- [JNI]开发实例(1)封装libjpeg库 保证图片质量压缩图片
- 微信公众号根据URL取文章详情 API 返回值说明
- 第09章 网格划分自我附加练习-2:圆角结构 、圆柱结构、三角结构划分:
- IReader Silverlight电子阅读器介绍开源项目
- 张飞电子工程师速成视频教程百度云_张飞电子工程师速成视频教程第二部
- Provisional headers are shown axios 超时处理
- kali 密码破解汇总
- Python模拟登陆强智教务以及使用(持续更新中)
- (附源码)ssmJavaEE无人机数据管理系统 毕业设计 111022
- 程序存储器 指令寄存器 程序计数器 地址寄存器
- 然而,随着下属人数的增多,下属各自 开始形成自己的权力主体。
- Python 爬虫心得
- 指针 Swap交换函数
- 计算机二级考试地点没有容量,2017年计算机二级office考试点积累
- 单片机c语言 步进电机,步进电机控制(单片机C语言).doc