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 ...
随机推荐
- Kafka,RocketMQ,RabbitMQ部署与使用体验
前言 近期在研究各种消息队列方案,为了有一个直观的使用体验,我把Kafka,RocketMQ,RabbitMQ各自部署了一遍,并使用了最基本的生产与消费消息功能.在部署过程中也遇到一些问题,特此记录. ...
- 路由与交换,cisco路由器配置,浮动静态路由
设置浮动静态路由的目的就是为了防止因为一条线路故障而引起网络故障.言外之意就是说浮动静态路由实际上是主干路由的备份.例如下图: 假如我们设路由器之间的串口(seria)为浮动静态路由(管理距离为100 ...
- JAVA中的==和queals()的区别
一.先来说说Java的基本数据类型和引用类型 八大基本数据类型:Byte,short,int,long,double,folat,boolean,char,其中占一个字节的是byte,short和ch ...
- python连接mysql中文数据编码
系统是win7 x64 Python 2.7.6的site.py里面编码设定为 utf-8 py文件首行指定 #coding:utf-8 MySQL 5.5.38安装时指定代码为utf-8 peewe ...
- 06-jmeter参数化(函数对话框使用)
概念: 1.变量命名的规则:字母.下划线开头,可包含数字,严格区分大小写 2.配置元件:用户定义的变量-------值是不变化的 用户命名的参数--------可以动态获取的并传参的 jmeter函数 ...
- syncronized如何上锁
上锁,根据操作系统所说的原则,对共享变量上锁,对临界区上锁.谁访问临界资源?就给谁上锁 同步监视器,它上锁的对象. 1.用关键字给方法上锁 2.用synchronized代码块上锁 默认上锁对象:th ...
- C语言小练习之学生信息管理系统
C语言小练习之学生信息管理系统 main.c文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2 ...
- AJ学IOS(09)UI之UIScrollView代理触摸实现_图片缩放
AJ分享,必须精品 先看效果 代码 // // NYViewController.m // 05-放大缩小图片UIScrollView // // Created by apple on 15-3-2 ...
- 做一个通过dockerfile从零构建centos7.4
今天做一个dockerfile从零构建centos7.4镜像 废话不多说,很简单. 需要的软件包:centos7.4的rootfs 链接:提取码:usnu 下载以后我们打开看看里面是什么呢: 可以看的 ...
- I. Same String
有两个只由小写字母组成的长度为n的字符串s1,s2和m组字母对应关系,每一组关系由两个字母c1和c2组成,代表c1可以直接变成c2,你需要判断s1是否可以通过这m组关系转换为s2. 输入格式 第一行输 ...