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(这题鸽了)的更多相关文章

  1. CF思维联系--CodeForces - 218C E - Ice Skating (并查集)

    题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his ...

  2. CF思维联系– CodeForces - 991C Candies(二分)

    ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...

  3. CF思维联系–CodeForces - 225C. Barcode(二路动态规划)

    ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...

  4. CF思维联系–CodeForces -224C - Bracket Sequence

    ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", ...

  5. 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 ...

  6. CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)

    ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...

  7. CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)

    ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...

  8. 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 ...

  9. Codeforces#441 Div.2 四小题

    Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...

随机推荐

  1. Android 添加键值并上报从驱动到上层

    转载:https://blog.csdn.net/weixin_43854010/article/details/94390803 Android 添加键值并上报从驱动到上层 平台 :RK3288 O ...

  2. (js描述的)数据结构[集合结构](6)

    (js描述的)数据结构[集合结构](6) 一.集合结构特点 1.集合中的元素不能重复. 2.集合是无序的. 二.集合的代码实现 function Set() { this.items = {} //1 ...

  3. 好消息,vue3.0 进入 beta 阶段!

    昨天,4 月 16 日,vue 3 正式进入 beta 阶段.同日,尤大参加了 State of Vue 的线上活动,以下是他上传到 google docs 上的 slides : State of ...

  4. Cilium使用 (Cilium 3)

    使用k3s测试Cilium,安装步骤可以参见官方文档 Cilium安装使用 docker安装 使用如下命令安装最新版本的docker yum install -y yum-utils \ device ...

  5. 这本最适合夯实基础的经典 Java 书籍,可能80% 的 Java 程序员没有认真看过!

    公众号[程序员书单]出品,转载请注明出处 作者:黄小斜 今天要给大家带来的一本书,是大名鼎鼎的head first系列丛书的一本<head first Java>相信很多学习Java的朋友 ...

  6. VCL安装有哪几种方法?

    不是由Borland 提供的组件叫第三方组件: 就目前常见的各种形式的组件的安装方法介绍一下. 1.只有一个DCU文件的组件.DCU文件是编译好的单元文件,这样的组件是作者不想把源码公布.一般来说,作 ...

  7. stand up meeting 12-2

    今天因为各位组员组里项目原因没有集中在一起进行stand up meeting.但是士杰和天赋国庆分别对项目进度和前后端的结合进行的沟通. 针对后端部分,天赋完成了GetRankingData API ...

  8. Java匹马行天下之JavaSE核心技术——异常处理

    Java匹马行天下之JavaSE核心技术——异常处理 异常的简介 在Java中,异常就是Java在编译.运行或运行过程中出现的错误. 程序错误分为三种:编译错误.运行时错误和逻辑错误 编译错误是因为程 ...

  9. 最短路径变形 POJ 2253

    Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...

  10. Python——详解__slots__,property和私有方法

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是Python专题的第11篇文章,我们来聊聊面向对象的一些进阶使用. __slots__ 如果你看过github当中一些大牛的代码,你会 ...