CF思维联系–CodeForces-217C C. Formurosa(这题鸽了)
ACM思维题训练集合
The Bytelandian Institute for Biological Research (BIBR) is investigating the properties of two species of bacteria, named simply 0 and 1. Even under a microscope, bacteria of those two species are very difficult to distinguish. In fact, the only thing the scientists possess that is able to differentiate between them is a plant called Formurosa.
If the scientists place a sample of colonies of bacteria on each on Formurosa’s leaves, it will activate a complicated nutrition process. During that process color of Formurosa changes to reflect the result of a — possibly very complicated — logical formula on the species of bacteria, involving constants and the operators | (OR), & (AND) and ^ (XOR). If it is 0, the plant will turn red, otherwise — it will turn blue.
For example, if the nutrition process of Formurosa is described by the formula: (((??)|?)&(1?)); then Formurosa has four leaves (the “?” signs denote the leaves). If we place 0, 1, 0, 0 on the respective leaves, the result of the nutrition process will be (((01)|0)&(10)) = 1, therefore the plant will turn blue.
The scientists have n colonies of bacteria. They do not know their types; the only thing they know for sure is that not all colonies are of the same type. They want to attempt to determine the bacteria’s species by repeated evaluations with Formurosa. During each evaluation they must place exactly one sample on every leaf of the plant. However, they may use multiple samples of one colony during a single evaluation; they can even cover the whole plant with bacteria from one colony!
Is it possible for them to always determine the species of each colony, no matter what they are (assuming they are not all the same)?
Input
The first line of input contains a single integer n (2 ≤ n ≤ 106) — the number of colonies of bacteria.
The second line contains the formula describing the nutrition process of Formurosa. This line contains only characters «0», «1», «?», «|», «&», «^», «(», «)» and complies with the following grammar:
s → 0|1|?|(s|s)|(s&s)|(s^s)
The formula consists of no more than 106 characters.
Output
If it is always possible to determine the species of each colony, output “YES” (without quotes). Otherwise, output “NO” (without quotes).
Examples
inputCopy
2
(?^?)
outputCopy
NO
inputCopy
10
?
outputCopy
YES
inputCopy
2
((?^?)&?)
outputCopy
YES
这题没看懂,做了三天,发现自己理解错了,鸽子了,抱歉,放个题解把。
#include <stdio.h>
char str[2000000];
struct Ans
{
int stat;
int len;
};
int bxor (int a, int b)
{
int re = 0;
for (int i = 0; i < 16; i ++)
if (a & (1 << i))
for (int j = 0; j < 16; j ++)
if (b & (1 << j))
{
re |= (1 << (i ^ j));
}
return re;
}
int bor (int a, int b)
{
int re = 0;
for (int i = 0; i < 16; i ++)
if (a & (1 << i))
for (int j = 0; j < 16; j ++)
if (b & (1 << j))
{
re |= (1 << (i | j));
}
return re;
}
int band (int a, int b)
{
int re = 0;
for (int i = 0; i < 16; i ++)
if (a & (1 << i))
for (int j = 0; j < 16; j ++)
if (b & (1 << j))
{
re |= (1 << (i & j));
}
return re;
}
bool isok (Ans ans)
{
if (ans.stat & (1 << (8 + 4 + 2)))
return true;
if (ans.stat & (1 << (8 + 4 + 1)))
return true;
if (ans.stat & (1 << (8 + 2 + 1)))
return true;
if (ans.stat & (1 << (4 + 2 + 1)))
return true;
if (ans.stat & (1 << (8 + 4)))
return true;
if (ans.stat & (1 << (8 + 2)))
return true;
if (ans.stat & (1 << (4 + 1)))
return true;
if (ans.stat & (1 << (2 + 1)))
return true;
if (ans.stat & (1 << (8)))
return true;
if (ans.stat & (1 << (4)))
return true;
if (ans.stat & (1 << (2)))
return true;
if (ans.stat & (1 << (1)))
return true;
return false;
}
Ans getans (int start)
{
Ans ans;
if (str[start] == '0')
{
ans.stat = (1 << 0);
ans.len = 1;
return ans;
}
if (str[start] == '1')
{
ans.stat = (1 << 15);
ans.len = 1;
return ans;
}
if (str[start] == '?')
{
ans.stat = (1 << (8+2)) + (1 << (8+4));
ans.len = 1;
return ans;
}
Ans ans1, ans2;
char op;
start ++;
ans1 = getans (start);
start = start + ans1.len;
op = str[start ++];
ans2 = getans (start);
ans.len = ans1.len + ans2.len + 3;
if (op == '^')
ans.stat = bxor(ans1.stat, ans2.stat);
if (op == '&')
ans.stat = band(ans1.stat, ans2.stat);
if (op == '|')
ans.stat = bor(ans1.stat, ans2.stat);
return ans;
}
int main ()
{
int n;
scanf ("%d%s", &n, str);
printf ("%s\n", isok(getans (0))? "YES": "NO");
return 0;
}
CF思维联系–CodeForces-217C C. Formurosa(这题鸽了)的更多相关文章
- CF思维联系--CodeForces - 218C E - Ice Skating (并查集)
题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his ...
- CF思维联系– CodeForces - 991C Candies(二分)
ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...
- CF思维联系–CodeForces - 225C. Barcode(二路动态规划)
ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...
- CF思维联系–CodeForces -224C - Bracket Sequence
ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", ...
- CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)
ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to ...
- CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...
- CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...
- CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)
Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
随机推荐
- 汇编刷题:在M单元和N单元分别存有一个8位无符号数36H和95H,要求比较并输出 M大于N 或者 M小于N
DATA SEGMENT M DB 36H N DB 95H RESAULT1 DB 'M>N$' RESAULT2 DB 'M<N$' DATA ENDS ...
- 中阶 d06.1 cookie && session && jsp介绍
##Cookie > 饼干. 其实是一份小数据, 是服务器给客户端,并且存储在客户端上的一份小数据 ### 应用场景 > 自动登录.浏览记录.购物车. ###为什么要有这个Cookie & ...
- 22.3 Extends 构造方法的执行顺序
/** 1.有子父类继承关系的类中,创建父类对象未调用,执行父类无参构造* 2.有子父类继承关系的类中,创建子类对象未调用,执行顺序:默认先调用 父类无参构造---子类无参构造* 在子类的构造方法的第 ...
- leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution)
leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution) On a staircase, the i-th step ...
- java中JVM虚拟机内存模型详细说明
java中JVM虚拟机内存模型详细说明 2012-12-12 18:36:03| 分类: JAVA | 标签:java jvm 堆内存 虚拟机 |举报|字号 订阅 JVM的内部结构 ...
- Python 变量详解[学习 Python 必备基础知识][看此一篇就够了]
您的"关注"和"点赞",是信任,是认可,是支持,是动力...... 如意见相佐,可留言. 本人必将竭尽全力试图做到准确和全面,终其一生进行修改补充更新. 目录 ...
- Word文档创建目录
一.以设置两级目录为例: 1.设置两个标题,标题1对应第一级目录,标题2对应第二级目录. 点击标题1,点击修改: 设置好样式和格式: 同理设置标题2. 2.创建多级目录: 选择级别1,关联到标题1,设 ...
- 不同目录有同名proto文件情况下,protoc生成.cc/.h
首先先参考一下别人的博客,看完了,看懂了,再回过头来看我下面说的情况. 链接 https://blog.csdn.net/CAir2/article/details/78201572 但是这个也就是基 ...
- Python - 调用接口合并文件夹下多个Excel表
在工作中经常遇到需要打开许多个excel表格,然后合并的需求,合并的同时要求格式必须原汁原味的保留.利用VBA代码可以比较轻松的解决,现在我们来看Python中如何实现. 上代码: from open ...
- ajax ★ ★ ★ ★ ★
ajax 1 定义: 是创建交互式应用的网页交互技术 2 特点:无刷新.异步 3 中介数据类型: 1) XML - 可扩展的标记语言 ...