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 ...
随机推荐
- Vue 实战项目: 硅谷外卖(1)
第 1 章: 准备 1.1. 项目描述 1) 此项目为外卖 WebApp(SPA) 2) 包括商家, 商品, 购物车, 用户等多个子模块 3) 使用 Vue 全家桶+ES6+Webpack 等前端最新 ...
- Flask 入门(十三)
上文提到的Blueprint和厉害吧? 可是有个缺点,就是,还不够框架,因为一个功能不可能就一个文件啊?多文件怎么解决? 还和上文项目架构一样 1.新建两个目录,admin,function 2.ad ...
- 在MAC上如何使用SQL Server
由于小编在这学期要学习数据库原理这门课程,需要用到SQL Server,然而大家都知道SQL Server目前是只能在Windows上使用,我们在mac电脑上如何使用呢?我们可以借助目前比较火的Doc ...
- git tag命令
创建本地标签 git tag -a [tagname] -m [msg] git tag -a [tag_name] [commit_id] -m [msg] 创建远程标签 git push orig ...
- 搭建WEB、NFS共享、sersync实时同步以及全网定时备份服务流程
本次实验的主要目的: 1.搭建web服务,使用nfs服务共享的/data目录挂载到web站点目录上. 2.nfs服务器与backup服务器使用sersync实时同步/data目录中的文件. 3.bac ...
- Apache SkyWalking
Apache SkyWalking 什么是 SkyWalking SkyWalking 是观察性分析平台和应用性能管理系统. 提供分布式追踪.服务网格遥测分析.度量聚合和可视化一体化解决方案. 支持J ...
- JuiceSSH:安卓平台免费好用的 SSH 客户端
为了解决上下班路上或者没带电脑时,查看 Linux 服务器日志或者紧急运维的需求,最终找到了 JuiceSSH 这款软件,强烈推荐给大家. 简介 JuiceSSH 是一个为 Android 打造的全功 ...
- 模仿NetFlix首页效果
之前写过UWP 带左右滚动按钮的横向ListView———仿NetFlix首页河的设计,讲述了如何设计一个带有左右滚动按钮横向的ListView. 不过我在半年之前挖了一个坑,由于工作关系,没时间来填 ...
- unity3d的键盘和鼠标输入
一.键盘的输入 •GetKey,GetKeyDown,GetKeyUp三个方法分别获取用户键盘按键的输入 1. GetKey:用户长按按键有效: bool down = Input.GetKeyDow ...
- Problem L. World Cup
题目大意:有A,B,C,D四个队伍,两两之间有一个比赛,假如A和B比赛,如果平局,各加一分,如果说A胜,给A加3分,不给B加分,B胜同理 给出A,B,C,D,的得分,判断形成这种局面有多少种方式. 思 ...