位运算,枚举。

按按分开计算,枚举$?$是$0$还是$1$,分别计算出$sum$,然后就可以知道该位需要填$1$还是$0$了。

#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std; int n,m;
char s[][];
map<string,int>z;
char t[]; int ans1[],ans2[]; int q[]; struct X
{
int op;
int x1,x2;
}p[]; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%s",t);
z[t]=i;
scanf("%s",t); scanf("%s",t);
if(t[]==''||t[]=='')
{
p[i].op=;
strcpy(s[i],t);
}
else
{
if(t[]=='?') p[i].x1=-;
else p[i].x1 = z[t]; scanf("%s",t);
if(t[]=='O') p[i].op=;
if(t[]=='X') p[i].op=;
if(t[]=='A') p[i].op=; scanf("%s",t);
if(t[]=='?') p[i].x2=-;
else p[i].x2 = z[t];
}
} for(int j=;j<m;j++)
{
int sum[]; sum[]=sum[]=;
for(int tx=;tx<=;tx++)
{
for(int i=;i<=n;i++)
{
if(p[i].op==) q[i] = s[i][j]-'';
else
{
int x1 = p[i].x1, x2 = p[i].x2;
if(x1==-) x1 = tx; else x1 = q[x1];
if(x2==-) x2 = tx; else x2 = q[x2]; if(p[i].op==) q[i] = (x1|x2);
else if(p[i].op==) q[i] = (x1^x2);
else if(p[i].op==) q[i] = (x1&x2);
}
}
for(int i=;i<=n;i++) sum[tx]+=q[i];
} if(sum[]==sum[]) ans1[j]=ans2[j]=;
else if(sum[]<sum[]) ans1[j]=,ans2[j]=;
else ans1[j]=,ans2[j]=;
} for(int i=;i<m;i++) printf("%d",ans1[i]); printf("\n");
for(int i=;i<m;i++) printf("%d",ans2[i]); printf("\n"); return ;
}

CodeForces 779E Bitwise Formula的更多相关文章

  1. CodeForces 778B - Bitwise Formula

    题意: 选择一个 m 位的二进制数字,总分为 n 个算式的答案之和.问得到最低分和最高分分别应该取哪个二进制数字 分析: 因为所有数字都是m位的,高位的权重大于低位 ,我们就从高到低考虑 ans 的每 ...

  2. 【codeforces 779E】Bitwise Formula

    [题目链接]:http://codeforces.com/contest/779/problem/E [题意] 给你n个长度为m的二进制数 (有一些是通过位运算操作两个数的形式给出); 然后有一个未知 ...

  3. Codeforces Problem 778B Bitwise Formula

    题目链接:http://codeforces.com/contest/779/problem/E 题意:有n个变量都可以用m位二进制数表示,这n个数的value将以两种格式中的一种给出 1.变量名, ...

  4. 【推导】【贪心】Codeforces Round #402 (Div. 2) E. Bitwise Formula

    按位考虑,每个变量最终的赋值要么是必为0,要么必为1,要么和所选定的数相同,记为2,要么和所选定的数相反,记为3,一共就这四种情况. 可以预处理出来一个真值表,然后从前往后推导出每个变量的赋值. 然后 ...

  5. CF778B(round 402 div.2 E) Bitwise Formula

    题意: Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied t ...

  6. Codeforces 1408I - Bitwise Magic(找性质+集合幂级数)

    Codeforces 题面传送门 & 洛谷题面传送门 Yet another immortal D1+D2 I %%%%%% 首先直接统计肯定是非常不容易的,不过注意到这个 \(k\) 非常小 ...

  7. CodeForces 1408I Bitwise Magic

    题意 给定三个整数 \(n,k,c\) 和一个长度为 \(n\) 的序列 \(a\),保证 \(a_i\) 互不相同.可以操作 \(k\) 次,每次随机选择一个 \(a_i\) 变成 \(a_i-1\ ...

  8. Codeforces Round #402 (Div. 1)

    A题卡壳了,往离线倒着加那方面想了会儿,后来才发现方向错了,二十多分钟才过掉,过了B后做D,想法好像有点问题,最后只过两题,掉分了,差一点回紫. AC:AB Rank:173 Rating:2227- ...

  9. Codeforces Round#402(Div.1)掉分记+题解

    哎,今天第一次打div1 感觉头脑很不清醒... 看到第一题就蒙了,想了好久,怎么乱dp,倒过来插之类的...突然发现不就是一道sb二分吗.....sb二分看了二十分钟........ 然后第二题看了 ...

随机推荐

  1. 游戏编程入门之Bomb Catcher游戏

    首先是代码: MyDirectX.h: #pragma once //header file #define WIN32_EXTRA_LEAN #define DIRECTINPUT_VERSION ...

  2. ICPC2017 Urumqi - K - Sum of the Line

    题目描述 Consider a triangle of integers, denoted by T. The value at (r, c) is denoted by Tr,c , where 1 ...

  3. iOS 隐藏/显示导航栏

    一.隐藏导航栏 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBa ...

  4. elasticsearch中Node的创建

    要连接到集群,首先要告诉集群:你是谁,你有什么特征.在es中体现为实例化节点,elasticsearch通过org.elasticsearch.node.NodeBuilder的build()或者no ...

  5. 【BZOJ4373】算术天才⑨与等差数列 [线段树]

    算术天才⑨与等差数列 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 算术天才⑨非常喜欢和等 ...

  6. 【BZOJ4884】太空猫 [DP]

    太空猫 Time Limit: 1 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 太空猫(SpaceCat)是一款画面精 ...

  7. NGINX: Primary script unknown

    参考: [ StackExchange ] 这里的解决方式应该是你排查了所有原因依然无法解决问题. SELINUX 更改 selinux 配置 chcon -R -t httpd_sys_conten ...

  8. 【HNOI】 攻城略池 tree-dp

    [题目大意] 给定一棵树,边有边权,每个节点有一些兵,现在叶子节点在0时刻被占领,并且任意节点在x被占领,那么从x+1开始,每单位时间产生一个兵,兵会顺着父亲节点一直走到根(1),其中每经过一个节点, ...

  9. bootstrap 弹窗 数据清除

    bootstrap modal操作简单易用, //清除弹窗原数据 $("#create_modal").on("hidden.bs.modal", functi ...

  10. Python模块学习 - IPy

    简介 在IP地址规划中,涉及到计算大量的IP地址,包括网段.网络掩码.广播地址.子网数.IP类型等,即便是专业的网络人员也要进行繁琐的计算,而IPy模块提供了专门针对IPV4地址与IPV6地址的类与工 ...