2101: Bake Off
Description
Davy decided to start a weekend market stall where he sells his famous cakes. For the first market stall, Davy decided to bake n cakes. Each cake is described by its deliciousness and the flavours it contains, which is a (possibly empty) subset of the flavours {caramel, cherry, chocolate, cinnamon, coconut, cookies}. Because of Davy’s skill in baking, he has a line of m customers when he opens his stall who wish to buy a cake. Davy will serve them in the order they are lined up. Each customer has a required subset of flavours they would like in their cake, but are happy to receive additional flavours in their cake. Davy will give each customer the most delicious cake left that contains at least the flavours that the customer has asked for. You should help Davy determine which cake to sell to each customer (or if there is no cake that satisfies that customer’s requirements, in which case, they buy nothing).
Input
The first line contains two integers n (1 ≤ n ≤ 300 000), which is the number of cakes, and m (1 ≤ m ≤ 100 000), which is the number of customers. The next 6 lines describe the flavours contained in the cakes. The first of these lines contains a string of length n, which describes if caramel is in each cake. This string will contain a 1 in the ith position if cake i contains caramel and 0 otherwise. The second through sixth of these lines will describe cherry, chocolate, cinnamon, coconut and cookies, respectively, in the same format. The cakes are numbered from left to right, starting with cake 1 on the left. No two cakes have the same deliciousness and are sorted by their deliciousness, with cake 1 being the least delicious and cake n being the most delicious. The next 6 lines describe the flavours requested by the customers. The first of these lines contains a string of length m, which describes if each customer has requested caramel in their cake. This string will contain a 1 in the ith position if customer i requested caramel and 0 otherwise. The second through sixth of these lines will describe cherry, chocolate, cinnamon, coconut and cookies, respectively, in the same format.
Output
Display the number of the cake purchased by each customer in the order that they are requested. If a customer does not purchase a cake, display -1 for them instead.
Sample Input
4 2
0001
1111
0001
1111
0001
1111
01
11
01
11
01
11 3 4
000
000
000
010
101
110
0000
0000
0000
0010
1000
0100
Sample Output
4 -1 3 2 -1 1 这题 转化一下思路其实非常好写, vector很好用 ,
先进行一下二进制转化 , 然后可以发现 与 运算非常好用
因为 111111 最多才63 可以暴力用一个vector【70】维护
然后排序 ,每次都找下标最大的 ,然后erase掉 (这就是vector舒服的地方了)
其实和优先队列的思想差不多
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
const int maxn = 1e5 + ; char cake[][ * maxn], peo[][maxn];
int a[ * maxn], b[maxn];
vector<int>p[];
int main() {
int n, m;
while(scanf("%d%d", &n, &m) != EOF) {
for (int i = ; i < ; i++) p[i].clear();
for (int i = ; i < ; i++)
scanf("%s", cake[i]);
for (int i = ; i < n ; i++)
a[i] = (cake[][i] - '') * + (cake[][i] - '') * + (cake[][i] - '') * + (cake[][i] - '') * + (cake[][i] - '') * + (cake[][i] - '') * ;
for (int i = ; i < ; i++)
scanf("%s", peo[i]);
for (int i = ; i < m ; i++)
b[i] = (peo[][i] - '') * + (peo[][i] - '') * + (peo[][i] - '') * + (peo[][i] - '') * + (peo[][i] - '') * + (peo[][i] - '') * ;
for (int i = ; i < n ; i++)
p[a[i]].push_back(i + );
for (int i = ; i < ; i++)
sort(p[i].begin(), p[i].end());
for (int i = ; i < m ; i++) {
int ans = -, idx;
for (int j = b[i] ; j < ; j++) {
if ( (j & b[i]) != b[i] ) continue;
if (p[j].size() == ) continue;
if (ans < p[j][p[j].size() - ]) {
ans = p[j][p[j].size() - ];
idx = j;
}
}
printf("%d ", ans);
if (ans != -) p[idx].erase(p[idx].end() - );
}
printf("\n");
}
return ;
}
2101: Bake Off的更多相关文章
- Mesh.Bake Scaled Mesh PhysX CollisionData的性能问题
最近在做项目优化时,遇到Mesh.Bake Scaled Mesh PhysX CollisionData这个问题,随手记录一下. profiler中显示的cpu波峰瓶颈中,Mesh.Bake Sca ...
- BZOJ 2101: [Usaco2010 Dec]Treasure Chest 藏宝箱( dp )
dp( l , r ) = sum( l , r ) - min( dp( l + 1 , r ) , dp( l , r - 1 ) ) 被卡空间....我们可以发现 l > r 是无意义的 ...
- TJU Problem 2101 Bullseye
注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...
- Unity3D规则之Unity Root Motion / Bake into Pose 的问题
参考: http://ru.unity3d-docs.com/Documentation/Manual/Animator.html http://ru.unity3d-docs.com/Documen ...
- Unity编辑器 - Rigidbody动力学Bake到AnimationClip
Unity编辑器 - Rigidbody动力学Bake到AnimationClip Unity文档移动平台优化部分提到Physics对CPU的消耗较大 将动力学的特效如破碎等Bake成动画也是优化性能 ...
- 【BZOJ】2101: [Usaco2010 Dec]Treasure Chest 藏宝箱(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=2101 这个dp真是神思想orz 设状态f[i, j]表示i-j先手所拿最大值,注意,是先手 所以转移 ...
- 【cocos2d-js官方文档】三、Bake功能使用说明
设计意图 在游戏开发的过程中,经常会遇到作为UI或者不怎么修改的背景的层(Layer), 这些层内容并不怎么变动. 而在游戏的渲染过程中,这些层往往又会消耗大量的渲染时间,特别是比较复杂的UI界面,比 ...
- BZOJ 2101 [Usaco2010 Dec]Treasure Chest 藏宝箱:区间dp 博弈【两种表示方法】【压维】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2101 题意: 共有n枚金币,第i枚金币的价值是w[i]. 把金币排成一条直线,Bessie ...
- BZOJ——2101: [Usaco2010 Dec]Treasure Chest 藏宝箱
http://www.lydsy.com/JudgeOnline/problem.php?id=2101 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: ...
随机推荐
- 根据isbn获得图书的所有信息
几点说明 1这个豆瓣的api https://api.douban.com/v2/book/isbn/:9787549208869 可以以json的形式返回书籍的所有信息 2最开始的时候是我自己写的用 ...
- Gradle 1.12用户指南翻译——第四十二章. Announce插件
本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- git分享:Git_MinaPro
Apache MINA+MyBatis+EHcache定制开发,实现终端设备数据的实时接收解析存储. <项目运行:打包下载所有文件导入Eclipse,将datapro.sql导入mysql数据库 ...
- 基于event 实现的线程安全的优先队列(python实现)
event 事件是个很不错的线程同步,以及线程通信的机制,在python的许多源代码中都基于event实现了很多的线程安全,支持并发,线程通信的库 对于优先队列的堆实现,请看<python下实现 ...
- JVM学习--(三)配置参数
JVM配置参数分为三类参数: 1.跟踪参数 2.堆分配参数 3.栈分配参数 这三类参数分别用于跟踪监控JVM状态,分配堆内存以及分配栈内存. 跟踪参数 跟踪参数用于跟踪监控JVM,往往被开发人员用于J ...
- nslookup查询结果详解
nslookup可以指定查询的类型,可以查到DNS记录的生存时间还可以指定使用那个DNS服务器进行解释.在已安装TCP/IP协议的电脑上面均可以使用这个命令.主要用来诊断域名系统 (DNS) 基础结构 ...
- js 逻辑运算符优化
运算符的代码优化,可以精简代码,提高代码可读性 下面主要讨论下逻辑运算符与 &&, 或||. 示例: 假设对成长速度显示规定如下: 成长速度为5显示1个箭头: 成长速度为10显示2个箭 ...
- Android Studio 2.3 instant run与miui冲突问题的解决
Android Studio最近发布的2.3版本,由于这个版本改进后的Instant Run功能和很多国内ROM存在兼容问题,所以导致不得不做一些妥协策略,具体在小米Rom上,就是把小米rom的调试定 ...
- 与班尼特·胡迪一起拿奖学金(HZNU-2273)
与班尼特·胡迪一起拿奖学金 AC Time Limit: 2 s Memory Limit: 256 MB Description 班尼特·胡迪这学期的体测终于上80分了,当期末考试的 ...
- spring的简单入门
spring是一个轻量级的JavaEE解决方案,是众多优秀设计模式的整合.spring的核心是:(工厂)容器 1.设计模式:解决一些特定问题的经典代码.共有23中设计模式(工厂,单例,代理,适配,装饰 ...