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. c# 删除程序占用的文件,强力删除文件,彻底删除文件,解除文件占用

    c# 删除程序占用的文件.清理删除文件.彻底删除文件,解除文件占用 文件打开时,以共享读写模式打开 FileStream inputStream = new FileStream(name, File ...

  2. Android 组件ContentProvider

    Android 组件ContentProvider Android的数据存储有五种方式Shared Preferences.网络存储.文件存储.外储存储.SQLite,一般这些存储都仅仅是在单独的一个 ...

  3. android recovery 主系统代码分析【转】

    本文转载自:http://blog.csdn.net/andyhuabing/article/details/9248713 阅读完上一篇文章: http://blog.csdn.net/andyhu ...

  4. Android系统Recovery工作原理之使用update.zip升级过程分析(八)---解析并执行升级脚本updater-script【转】

    本文转载自:http://blog.csdn.net/mu0206mu/article/details/7465551  Android系统Recovery工作原理之使用update.zip升级过程分 ...

  5. 3n+1问题

    #include <stdio.h> #include <math.h> // 算法竞赛的目标是编程对任意输入均得到正确的结果. // 请先独立完成,如果有困难可以翻阅本书代码 ...

  6. html5--视频播放器实例

    html5--视频播放器实例 总结: 1.相对定位和绝对定位的区别,两者都是浮起来了 2.属性和方法都是有对象的,搞清楚对象之后,属性和方法就很好用了,我们一般可以用document.getEleme ...

  7. tflearn中计算混淆矩阵方法——需要经过一步转换

    def do_rnn_wordbag(trainX, testX, trainY, testY): y_test=testY #trainX = pad_sequences(trainX, maxle ...

  8. Codeforces--630H--Benches(组合数)

    H - Benches Crawling in process... Crawling failed Time Limit:500MS     Memory Limit:65536KB     64b ...

  9. Mybatis:目录

    ylbtech-MyBatis:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbte ...

  10. 89. Ext.Button 按钮

    转自:http://www.cnblogs.com/lipan/archive/2011/12/13/2274797.html 从本篇开始讲基础控件,ExtJs对所有的UI控件都有它自己的一套封装.本 ...