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. C#如何正确的做深拷贝

    估计很多人在网上看到各种各样的DeepClone实现, 例如: 1. 通过BinaryFormatter进行二进制序列化 这玩意儿序列化出来的东西还带namespace类型, 尺寸非常大, 调试一下就 ...

  2. Flask 入门(七)

    flask操作数据库:建表: 承接上文: 修改main.py中的代码如下: #encoding:utf-8 from flask_sqlalchemy import SQLAlchemy from f ...

  3. 28.2 api-- System (gc、arraycopy、exit)

    /* * System:包含一些有用的类字段和方法.它不能被实例化 * static void arraycopy(Object src, int srcPos, Object dest, int d ...

  4. 数据库里账号的密码,需要怎样安全的存放?—— 密码哈希(Password Hash)

    最早在大学的时候,只知道用 MD5 来存用户的账号的密码,但其实这非常不安全,而所用到的哈希函数,深入挖掘,也发现并不简单-- 一.普通的 Hash 函数 哈希(散列)函数是什么就不赘述了. 1.不推 ...

  5. Chrome浏览器架构

    通用浏览器架构 它可以是一个具有许多不同线程的进程,也可以是具有几个通过IPC进行通信的多个线程的进程. 一个具有许多不同线程的进程 通过IPC进行通信的多个线程的进程 注意 这些不同的体系结构是实现 ...

  6. App 开发中判断 ios 和 andriod 常用方法便于修复在两类机型样式不一样等缺陷

    判断安卓, ios

  7. 弱智破解法——用python破解WIFI

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:李嘉图 PS:如有需要Python学习资料的小伙伴可以加点击下方链接自 ...

  8. ASE课程总结 by 冯晓云

    开始的开始,采访往届ASE班的blog:http://www.cnblogs.com/legs/p/4894362.html 和北航软工M1检查:http://www.cnblogs.com/legs ...

  9. lua使用笔记2:Linux 中安装php的lua扩展

    安装lua扩展的前提是lua已经安装好,如果没有安装,参照 1.http://pecl.php.net/package/lua 下载lua扩展 或者Linux下直接输入 wget http://pec ...

  10. abp(net core)+easyui+efcore实现仓储管理系统——入库管理之九(四十五)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...