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. MySql常用操作语句(1:启动、连接数据库及用户操作)

    下方将个人常用的MySql操作语句(Win7下)总结如下: 1. 启动与关闭数据库 “管理员”权限, MySql安装目录下bin目录//:  1.1 启动 @>net start mysql   ...

  2. OpenCV——PS 滤镜, 曝光过度

    算法原理可以参考: PS 滤镜,曝光过度 #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include <io ...

  3. java常用数据库连接池 (DBCP、c3p0、Druid) 配置说明

    1. 引言 1.1 定义 数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库 ...

  4. IOS Dev 需要常看的网站<转>

    英文系列 网站 http://Raywenderlich.com 这个不多说了吧,iOS界的百科全书.iOS By tutorial系列书从iOS7到8全买的正版别说499刀了,999刀也入手. ob ...

  5. Visual Studio 2013创建自定义多项目模版

    首先附上效果图: 可以看到输入解决方案名称后,自动创建了我事先写好的架构,并且项目名及Server层名称都变了,并且依然保持了引用关系. 下面讲具体步骤: 第一步:建立解决方案,并将需要的代码全部写好 ...

  6. 【转载】tomcat+nginx+redis实现均衡负载、session共享(二)

    今天我们接着说上次还没完成session共享的部分,还没看过上一篇的朋友可以先看下上次内容,http://www.cnblogs.com/zhrxidian/p/5432886.html. 1.red ...

  7. Spring温故而知新 - bean的装配(续)

    按条件装配bean 就是当满足特定的条件时Spring容器才创建Bean,Spring中通过@Conditional注解来实现条件化配置bean package com.sl.ioc; import ...

  8. win10安装wmi报错问题

    在win10上,安装wmi,首先下载https://pypi.python.org/pypi/WMI/#downloads,将wmi下载下来 安装过程中,会报错,No Python installat ...

  9. 基于one2team框架的Highcharts图表图片导出方案

    这篇文章已经没有什么意义了,新版的HIghcharts提供Java图片导出解决方案,你需要做的就是下个Maven,bulid一个war就Ok了.---addedy on 2012-11-15 多说一句 ...

  10. FPGA图像处理之行缓存(linebuffer)的设计一

    FPGA图像处理之行缓存(linebuffer)的设计一 作者:OpenS_Lee 1 背景知识 在FPGA数字图像处理中,行缓存的使用非常频繁,例如我们需要图像矩阵操作的时候就需要进行缓存,例如图像 ...