Oleg and Little Ponies

Time limit: 0.9 second
Memory limit: 64 MB
Little boy Oleg loves the cartoon My Little Pony. How it cannot be loved, because there is friendship, magic and colored horses!
For the past several months Oleg has been begging from his parents a real pony, but they are just ready to buy him only collectible figures of cartoon characters. With these figures Oleg recreates the best episodes of My Little Pony on his desk. Sometimes he realizes that he has already all the key characters for the next episode, and begins to feel the desire to immediately buy the missing figures for this episode. For example, if Oleg has on hand Twilight Sparkle and Spike, his life will not be sweet without Princess Celestia. It may happen that the new figures will cause new desires: having three above-mentioned figures, Oleg will want Nightmare Moon.
For convenience, let’s number all the figures with integers from 1 to n. Then the Oleg’s desirewill be described by two sets of numbers {a1, ..., ak} and {b1, ..., bt}, which means that if he already has figures with numbers a1, ..., ak, he also wants figures with numbers b1, ..., bt.
Oleg’s parents in order to distract him from his desires of real pony are ready to buy him as many figures as he wants. But they want to buy a set of figures that will satisfy all the desires of Oleg, in a single purchase. Of course, parents will not buy the extra figures.
What figures will Oleg have after purchase?

Input

The first line contains integers n and m that are the number of figures and the number of Oleg’s desires (1 ≤ n ≤ 1000; 0 ≤ m ≤ 4000). The following m lines describe the desires. Each desire is given by two sets, separated by a space. A set is a string of n characters, each of that is “0” or “1”. The figure with number i is in the set, only when i-th character of the string is “1”. The last line contains the set of figures, which Oleg already has, in the same format.

Output

In a single line output a set of figures, which Oleg will have after purchase. In other words, it is the union of the set of the existing figures and the set of figures bought by parents. Output format is the same as in the input.

Sample

input output
6 4
111000 101000
110000 111000
010000 100000
000010 000001
010100
111100

Notes

In the example Oleg has already the figures 2 and 4. First, he wants the figure 1 (the third desire). If he gets it, he will want the figure 3 (the second desire). If you just buy him the figures 1 and 3, Oleg will not want anything more (the right part of the first desire consists of already existing figures, and the left side of the last desire is not fulfilled). Thus, after purchase Oleg will have figures with the numbers 1, 2, 3 and 4.
分析:bitset基本用法;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=1e3+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
inline void umax(int &p,int q){if(p<q)p=q;}
inline void umin(int &p,int q){if(p>q)p=q;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t;
bool flag;
set<int>ok;
vi tmp;
char b[maxn];
bitset<maxn>a[maxn<<],c[maxn<<],ans;
inline void gao(int p)
{
if((ans&a[p])!=a[p])return;
ans|=c[p];
tmp.pb(p);
flag=true;
}
int main()
{
int i,j;
scanf("%d%d",&n,&m);
rep(i,,m)
{
scanf("%s",b);
ok.insert(i);
for(j=;b[j];j++)if(b[j]=='')a[i].set(j);
scanf("%s",b);
for(j=;b[j];j++)if(b[j]=='')c[i].set(j);
}
scanf("%s",b);
for(j=;b[j];j++)if(b[j]=='')ans.set(j);
rep(i,,m)gao(i);
for(int x:tmp)ok.erase(x);
while()
{
flag=false;
for(int x:ok)
{
gao(x);
}
if(!flag)break;
for(int x:tmp)ok.erase(x);
tmp.clear();
}
for(i=;i<n;i++)cout<<ans[i];
printf("\n");
return ;
}

Oleg and Little Ponies的更多相关文章

  1. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  2. Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008

    Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008 Pros and Cons of T4 in Visual Studio 2008 Po ...

  3. Interview with Oleg

    Interview with Oleg time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. C - Oleg and shares

    Problem description Oleg the bank client checks share prices every day. There are n share prices he ...

  5. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. [CF738A]Interview with Oleg(模拟)

    题目链接:http://codeforces.com/contest/738/problem/A 题意:把ogo..ogo替换成***. 写的有点飘,还怕FST.不过还好 #include <b ...

  7. 【Codeforces】【网络流】【线段树】【扫描线】Oleg and chess (CodeForces - 793G)

    题意: 给定一个n*n的矩阵,一个格子上可以放一个车.其中有q个子矩阵,且q个子矩阵互不相交或者是重叠(但边界可以衔接).这q个子矩阵所覆盖的地方都是不能够放车的.车可以越过子矩阵覆盖的地方进行攻击( ...

  8. CodeForces 738A Interview with Oleg

    模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...

  9. 【codeforces 793A】Oleg and shares

    [题目链接]:http://codeforces.com/contest/793/problem/A [题意] 每次你可以对1..n中的任意一个数字进行减少k操作; 问你最后可不可能所有的数字都变成一 ...

随机推荐

  1. 在Twitter信息流中大规模应用深度学习——推文的相关度计算使用了深度学习

    我们如何对信息流进行排序? 在引入排序算法之前,信息流的组成非常简单:收集所有由你的关注对象在你最后一次登录Twitter之后发送的推文,再将它们按照时间倒序显示出来.这个看起来很简单,但要为数以亿计 ...

  2. CMS内容管理系统 -- WorkSpace

  3. JS代码放在哪里比较好!

    在页面上加上<script></script>只有2个地方:head中,body体中 如果外部的JS文件,在head中加,写页面特效js放在body后面. <html&g ...

  4. go之for循环

    一.基于计数器的迭代 格式 for 初始化语句; 条件语句; 修饰语句{} 实例 package main import "fmt" func main(){ for i:=0;i ...

  5. [SGU 199] Beautiful People

    [SGU 199] Beautiful People The most prestigious sports club in one city has exactly N members. Each ...

  6. Spring Boot (4) 静态页面和Thymeleaf模板

    静态页面 spring boot项目只有src目录,没有webapp目录,会将静态访问(html/图片等)映射到其自动配置的静态目录,如下 /static /public /resources /ME ...

  7. elasticsearch性能调优

    转载 http://www.cnblogs.com/hseagle/p/6015245.html 该es调优版本可能有低,但是思想主体不变,不合适的参数可以自己找最新的版本相应的替代,或者增删 ela ...

  8. 2.0 Linux系统的安装之Fedora安装单系统(2)

    2.0 Linux系统的安装之Fedora安装单系统(2) *Linux系统的安装之Fedora安装单系统 恐怕最好装的系统就是Linux系统了,或者与Windows并列.此篇教程为Fedora的单系 ...

  9. 联想笋尖S90(S90-t 、S90-u)解锁BootLoader

    工具下载链接: http://pan.baidu.com/s/1eSgZuka 备用下载链接: http://pan.baidu.com/s/1dFKqSId 本篇教程,仅限于联想笋尖S90(S90- ...

  10. Runtime的相关知识

    Runtime是近年来面试遇到的一个高频方向,也是我们平时开发中或多或少接触的一个领域,那么什么是runtime呢?它又可以用来做什么呢? 什么是Runtime?平时项目中有用过么? OC是一门动态性 ...