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的更多相关文章

  1. Mesh.Bake Scaled Mesh PhysX CollisionData的性能问题

    最近在做项目优化时,遇到Mesh.Bake Scaled Mesh PhysX CollisionData这个问题,随手记录一下. profiler中显示的cpu波峰瓶颈中,Mesh.Bake Sca ...

  2. BZOJ 2101: [Usaco2010 Dec]Treasure Chest 藏宝箱( dp )

    dp( l , r ) = sum( l , r ) - min( dp( l + 1 , r ) , dp( l , r - 1 ) ) 被卡空间....我们可以发现 l > r 是无意义的 ...

  3. TJU Problem 2101 Bullseye

    注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...

  4. Unity3D规则之Unity Root Motion / Bake into Pose 的问题

    参考: http://ru.unity3d-docs.com/Documentation/Manual/Animator.html http://ru.unity3d-docs.com/Documen ...

  5. Unity编辑器 - Rigidbody动力学Bake到AnimationClip

    Unity编辑器 - Rigidbody动力学Bake到AnimationClip Unity文档移动平台优化部分提到Physics对CPU的消耗较大 将动力学的特效如破碎等Bake成动画也是优化性能 ...

  6. 【BZOJ】2101: [Usaco2010 Dec]Treasure Chest 藏宝箱(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2101 这个dp真是神思想orz 设状态f[i, j]表示i-j先手所拿最大值,注意,是先手 所以转移 ...

  7. 【cocos2d-js官方文档】三、Bake功能使用说明

    设计意图 在游戏开发的过程中,经常会遇到作为UI或者不怎么修改的背景的层(Layer), 这些层内容并不怎么变动. 而在游戏的渲染过程中,这些层往往又会消耗大量的渲染时间,特别是比较复杂的UI界面,比 ...

  8. BZOJ 2101 [Usaco2010 Dec]Treasure Chest 藏宝箱:区间dp 博弈【两种表示方法】【压维】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2101 题意: 共有n枚金币,第i枚金币的价值是w[i]. 把金币排成一条直线,Bessie ...

  9. BZOJ——2101: [Usaco2010 Dec]Treasure Chest 藏宝箱

    http://www.lydsy.com/JudgeOnline/problem.php?id=2101 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit:  ...

随机推荐

  1. navicat里导入和导出.sql文件

    一:Navicat导入MySQL的.sql文件. 打开连接connection,选择你要导入的数据库,双击打开(或者新建一个),然后右键该数据库,选"运行批次任务文件(execute sql ...

  2. Java学习网站大全

    Java学习网站 http://www-900.ibm.com/developerWorks/cn/java/index.shtml IBM的JAVA专题--永远的蓝色巨人 http://www.hu ...

  3. OpenCV+OpenCL stereo match 代码

    之前配置cuda跟opencv 的混合编程,发现只要使用的东西多半还要用opencv的代码编译一次,加上cuda的编译太浪费时间了,我看了几个博客,觉的opencl这个可能会比较好整,就把opencv ...

  4. Digogo ugdx文件的制作

    The openplatform source code is in old IT FTP server at "vte/KCD/20150814/openplatform_wallace. ...

  5. obj-c编程15[Cocoa实例03]:MVC以及归档化示例

    前面的博文里介绍了归档和解档,这里我们把它实际应用到一个简单的代码中去,将它作为一个多文档应用程序的打开和保存的背后支持.另外这里介绍一下MVC思想,这个在任何语言里都会有,它是一种设计思想,主要可以 ...

  6. HDFS的java api操作

    hdfs在生产应用中主要是针对客户端的开发,从hdfs提供的api中构造一个HDFS的访问客户端对象,然后通过该客户端对象操作(增删改查)HDFS上的文件. 搭建开发环境 方式一(windows环境下 ...

  7. asp.net 调试与iis部署的问题

    第一个问题:编译器错误信息: CS0016: 未能写入输出文件"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET ...

  8. ionic1 sqlite的添加使用

    开始使用这个存储方式的原因是  之前用的Local Storage 存储在ios设备上  当内存达到一定程度时 ios会自动清除app的一部分存储 所以之前存的东西可能会被清除  达不到想要的功能效果 ...

  9. angularjs学习笔记之一

    directive 通过AngularJS模块API中的.directive()方法,我们可以通过传入一个字符串和一个函数来 注册一个新指令.其中字符串是这个指令的名字,指令名应该是驼峰命名风格的,函 ...

  10. java并发包分析之———BlockingQueue

    一.概述: BlockingQueue作为线程容器,可以为线程同步提供有力的保障.   二.BlockingQueue定义的常用方法 1.BlockingQueue定义的常用方法如下:   抛出异常 ...