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: ...
随机推荐
- Android开源经典项目
目前包括: Android开源项目第一篇--个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView. ...
- Windows核心编程读书笔记1
今天特别困啊,这是为什么?!!刚刚把第一章看了一下,困到不行,所以写blog清醒一下. 第一章标题是“错误处理”,看了之后吓了一跳,难道第一章就讲这么高大上的东西?!不是不是,我现在的理解是,这章主要 ...
- git分享:Git_MinaPro
Apache MINA+MyBatis+EHcache定制开发,实现终端设备数据的实时接收解析存储. <项目运行:打包下载所有文件导入Eclipse,将datapro.sql导入mysql数据库 ...
- gdb中的define命令
可以使用define命令达到类似于display的效果:比如每ni后显示当前5条指令: define s5 ni x/5i $pc end 甚至可以手动传入要显示指令的条数: define s ni ...
- Linux 系统应用编程——线程基础
传统多任务操作系统中一个可以独立调度的任务(或称之为顺序执行流)是一个进程.每个程序加载到内存后只可以唯一地对应创建一个顺序执行流,即传统意义的进程.每个进程的全部系统资源是私有的,如虚拟地址空间,文 ...
- Java IO学习--(二)文件
在Java应用程序中,文件是一种常用的数据源或者存储数据的媒介.所以这一小节将会对Java中文件的使用做一个简短的概述.这篇文章不会对每一个技术细节都做出解释,而是会针对文件存取的方法提供给你一些必要 ...
- Java不走弯路教程(6.JDBC)
6.JDBC 在上一章,我们完成了MyDb数据库的简单的客户段调用.作为产品我们还封装了驱动程序,并且提供了统一的调用接口. 大家应该知道,市面上有多种数据库产品,比如Oracle,Mysql,DB2 ...
- spring是如何管理 事务的
Spring提供的事务管理可以分为两类:编程式的和声明式的.编程式的,比较灵活,但是代码量大,存在重复的代码比较多:声明式的比编程式的更灵活方便. 1.传统使用JDBC的事务管理 以往使用JDBC ...
- Ajax的简单使用
仅介绍Ajax的使用,让入门小白快速上手 //请自行引入jQuery库文件 <script type="text/javascript"> $(function() { ...
- Markdown编辑技巧
[前言] 保存Markdown的编辑技巧,写博客随笔,可以用下. [正文] 1.空格 //半角空格(英文) //全角空格(中文)