博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oleg and Little Ponies
阅读量:5222 次
发布时间:2019-06-14

本文共 4362 字,大约阅读时间需要 14 分钟。

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, ..., 
a
k} and {
b1, ..., 
b
t}, which means that if he already has figures with numbers 
a1, ..., 
a
k, he also wants figures with numbers 
b1, ..., 
b
t.
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 4111000 101000110000 111000010000 100000000010 000001010100
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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define rep(i,m,n) for(i=m;i<=n;i++)#define mod 1000000007#define inf 0x3f3f3f3f#define vi vector
#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
#define Lson L, mid, ls[rt]#define Rson mid+1, R, rs[rt]#define sys system("pause")const int maxn=1e3+10;using namespace std;ll gcd(ll p,ll q){ return q==0?p:gcd(q,p%q);}ll qpow(ll p,ll q){ll f=1;while(q){ if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}inline void umax(int &p,int q){ if(p
q)p=q;}inline ll read(){ ll x=0;int f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int n,m,k,t;bool flag;set
ok;vi tmp;char b[maxn];bitset
a[maxn<<2],c[maxn<<2],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,1,m) { scanf("%s",b); ok.insert(i); for(j=0;b[j];j++)if(b[j]=='1')a[i].set(j); scanf("%s",b); for(j=0;b[j];j++)if(b[j]=='1')c[i].set(j); } scanf("%s",b); for(j=0;b[j];j++)if(b[j]=='1')ans.set(j); rep(i,1,m)gao(i); for(int x:tmp)ok.erase(x); while(1) { flag=false; for(int x:ok) { gao(x); } if(!flag)break; for(int x:tmp)ok.erase(x); tmp.clear(); } for(i=0;i
<

转载于:https://www.cnblogs.com/dyzll/p/6292489.html

你可能感兴趣的文章
SpringAop与AspectJ
查看>>
Leetcode 226: Invert Binary Tree
查看>>
http站点转https站点教程
查看>>
解决miner.start() 返回null
查看>>
关于MFC中窗口的销毁
查看>>
bzoj 2007: [Noi2010]海拔【最小割+dijskstra】
查看>>
BZOJ 1001--[BeiJing2006]狼抓兔子(最短路&对偶图)
查看>>
C# Dynamic通用反序列化Json类型并遍历属性比较
查看>>
128 Longest Consecutive Sequence 一个无序整数数组中找到最长连续序列
查看>>
定制jackson的自定义序列化(null值的处理)
查看>>
auth模块
查看>>
javascript keycode大全
查看>>
前台freemark获取后台的值
查看>>
log4j.properties的作用
查看>>
游戏偶感
查看>>
Leetcode: Unique Binary Search Trees II
查看>>
C++ FFLIB 之FFDB: 使用 Mysql&Sqlite 实现CRUD
查看>>
Spring-hibernate整合
查看>>
c++ map
查看>>
exit和return的区别
查看>>