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: ... 
随机推荐
- Mybatis批量插入、批量更新
			合理的使用批量插入.更新对优化有很大的作用,速度明显快了N倍. 数据库连接串后面要新增:&allowMultiQueries=true 批量插入的最大限制主要是看你整条sql占用的大小,所以可 ... 
- RHEL6.4安装nginx
			RHEL6.4安装nginx 下载nginx-1.6.1.tar.gz, 解压进入目录: $ yum install pcre-devel $ ./configure --with-http_ssl_ ... 
- DB Query Analyzer 6.01 is released, SQL Execute Schedule function can be used
			DB Query Analyzer is presented by Master Gen feng, Ma from Chinese Mainland. It has English versi ... 
- MR for  Baum-Welch algorithm
			The Baum-Welch algorithm is commonly used for training a Hidden Markov Model because of its superior ... 
- 类似Jquery ui 标签页(Tabs)
			<div class="indexnew_tit"> <a href="javascript:;" class="on"& ... 
- 【基础】CSS实现多重边框的5种方式
			简言 目前最优雅地实现多重边框的方案是利用CSS3 的 box-shadow属性,但如果要兼容老的浏览器,则需要选择其它的方案.本文简要地列举了几种多重边框的实现方案,大家可以根据项目实际及兼容性要求 ... 
- nslookup查询结果详解
			nslookup可以指定查询的类型,可以查到DNS记录的生存时间还可以指定使用那个DNS服务器进行解释.在已安装TCP/IP协议的电脑上面均可以使用这个命令.主要用来诊断域名系统 (DNS) 基础结构 ... 
- Hibernate中配置文件的学习
			首先我们看一下hibernate的主配置文件 <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Conf ... 
- R语言学习 第十一篇:日期和时间
			R语言的基础包中提供了三种基本类型用于处理日期和时间,Date用于处理日期,它不包括时间和时区信息:POSIXct/POSIXlt用于处理日期和时间,其中包括了日期.时间和时区信息.R内部在存储日期和 ... 
- ccf 目录格式转换
			任务背景: 在网络上获取的ccf目录的格式是PDF,但是要进行数据分析时,PDF格式的数据是不符合要求的,因此需要将pdf格式转化为excel格式 任务目的: 将pdf格式的CCF目录转化为excel ... 
