【SRM 717 div2 A】 NiceTable
Problem Statement
You are given a vector t that describes a rectangular table of zeroes and ones. Each character in t is either ‘0’ or ‘1’.
We say that a table is nice if there are two sequences x, y of zeroes and ones such that for each valid pair of indices i, j we have t[i][j] = x[i] xor y[j].
Some technical remarks:
The number of elements in x should be equal to the number of rows of the table, i.e., the number of elements in t.
The number of elements in y should be equal to the number of columns of the table, i.e., the length of each string in t.
The operation xor (exclusive or) is defined as follows: 0 xor 0 = 0, 1 xor 1 = 0, 0 xor 1 = 1, and 1 xor 0 = 1.
Verify whether the given table is nice. Return “Nice” if it is nice and “Not nice” otherwise. Note that the return value is case-sensitive.
Definition
Class:
NiceTable
Method:
isNice
Parameters:
vector
Returns:
string
Method signature:
string isNice(vector t)
(be sure your method is public)
Limits
Time limit (s):
2.000
Memory limit (MB):
512
Stack limit (MB):
512
Constraints
t will contain between 1 and 5 elements, inclusive.
Each element of t will contain between 1 and 5 characters, inclusive.
All elements of t will contain the same number of characters.
Each element of t will consist only of characters ‘0’ and ‘1’.
Examples
0)
{“01”,
“10”}
Returns: “Nice”
One valid choice is to choose x = y = {1, 0}.
1)
{“01”,
“11”}
Returns: “Not nice”
Assume that t is nice. The sequences x and y have to satisfy the following constraints:
x[0] xor y[0] = 0
x[0] xor y[1] = 1
x[1] xor y[0] = 1
x[1] xor y[1] = 1
From the first constraint we see that x[0] = y[0]. From the second and the third constraint we can then derive that we must also have x[1] = y[1]. But then the fourth constraint is not satisfied, which is a contradiction. Therefore, this t is not nice.
2)
{“0100”,
“1011”,
“0100”}
Returns: “Nice”
Here, one valid choice is x = {1, 0, 1} and y = {1, 0, 1, 1}.
3)
{“11”,
“10”,
“11”,
“11”,
“11”}
Returns: “Not nice”
【题目链接】:
【题意】
给你一个n*m的矩阵a;
然后问你是否存在一个长度为n的序列x和长度为m的序列y;
使得s[i]^s[j]=a[i][j]对于所有的i,j皆成立;
n,m<=5
a[i][j]中只会出现0和1
【题解】
暴力枚举x,y的每一位是0还是1就好;
【Number Of WA】
0
【反思】
一开始想错了,以为让x全都是0就好;
后来想,或许可以让x的第一位是0,然后其他位先不定;
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
//head
int x[8],y[8],hang,lie,ok;
vector <string> a;
void dfs2(int now){
if (now > lie-1){
int temp = 1;
rep1(i,0,hang-1){
rep1(j,0,lie-1){
int k = a[i][j]-'0';
if (k!=(x[i]^y[j]))
temp = 0;
}
}
if (temp) ok = 1;
return;
}
y[now] = 0;
dfs2(now+1);
y[now] = 1;
dfs2(now+1);
}
void dfs1(int now){
if (now > hang-1){
dfs2(0);
return;
}
x[now] = 0;
dfs1(now+1);
x[now] = 1;
dfs1(now+1);
}
class NiceTable
{
public:
string isNice(vector <string> t)
{
a = t;
hang = t.size(),lie = t[0].size();
ok = 0;
dfs1(0);
if (ok)
return "Nice";
else
return "Not nice";
}
};
【SRM 717 div2 A】 NiceTable的更多相关文章
- 【SRM 717 DIV2 C】DerangementsDiv2
Problem Statement You are given two ints: n and m. Let D be the number of permutations of the set {1 ...
- 【SRM 717 div2 B】LexmaxReplace
Problem Statement Alice has a string s of lowercase letters. The string is written on a wall. Alice ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- 【TP SRM 703 div2 250】AlternatingString
Problem Statement A string of zeros and ones is called an alternating string if no two adjacent char ...
- 【TP SRM 703 div2 500】 GCDGraph
Problem Statement You are given four ints: n, k, x, and y. The ints n and k describe a simple undire ...
- 【cf 483 div2 -C】Finite or not?(数论)
链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x ...
- 【市场调研与分析】Intel发力移动安全领域——By Me at 20140613
[市场调研与分析]Intel发力移动安全领域 ...
- 【疯狂造轮子-iOS】JSON转Model系列之二
[疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...
- 【疯狂造轮子-iOS】JSON转Model系列之一
[疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...
随机推荐
- 转:利用 T-sql 的从句 for xml path('') 实现多行合并到一行, 并带有分隔符
http://blog.csdn.net/rav009/article/details/50723307 T-sql 有一个for xml path('')的从句能把多行结果合并到一行,并成为xml ...
- C++12.1.4 类的前向声明、不完全类型类
只声明却没有定义的类称为—————–不完全类型,不完全类型不能定义该类型的对象,只能用于定义指向该类型的指针及引用,或者用于声明(不是定义)使用该类型作为形参类型或返回类型的函数. 在创建类的对象之前 ...
- luogu 4844 LJJ爱数数 (莫比乌斯反演+数学推导)
题目大意:求满足gcd(a,b,c)==1,1/a+1/b=1/c,a,b,c<=n的{a,b,c}有序三元组个数 因为题目里有LJJ我才做的这道题 出题人官方题解https://www.cnb ...
- pointer-events的css属性。使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为
pointer-events的css属性.使用该属性可以决定是否能穿透绝对定位元素去触发下面元素的某些行为,比如当一个元素盖住了某个点击事件时可用. 现在Firefox3.6+/Safari4+/Ch ...
- hadoop-02-关闭防火墙
hadoop-02-关闭防火墙 su root service iptables status #查看状态 即时关闭: service iptables stop #关闭 重启之后关闭: chkcon ...
- swift学习笔记(五)构造过程
构造过程是为了使用某个类.结构体或枚举类型的实例而进行的准备过程.在构造过程中,对每一个属性进行了初始值预设和其它必要的准备和初始化工作. 与OC相比,swift的构造函数.不须要返回值.同一时候,在 ...
- linux系统调用表(system call table)
系统调用号 函数名 入口点 源码 0 read sys_read fs/read_write.c 1 write sys_write fs/read_write.c 2 open sys_open f ...
- Windows API Hook
原文地址:http://blog.sina.com.cn/s/blog_628821950100xmuc.html 原文对我的帮助极大,正是由于看了原文.我才学会了HOOK.鉴于原文的排版不是非常好, ...
- 适配 iOS 8 时遇到的问题两则:远程推送和 Unwind Segue
原文:http://imtx.me/archives/1910.html 昨天我在微博上吐槽:iOS 8 / Xcode 6 真是史上对开发人员最糟糕的版本号了.收到非常多朋友表达同感. 之所以这么说 ...
- Mongodb集群之副本集
上篇咱们遗留了几个问题 1主节点是否能自己主动切换连接? 眼下须要手动切换 2主节点读写压力过大怎样解决 3从节点每一个上面的数据都是对数据库全量拷贝,从节点压力会不会过大 4数据压力达到机器支撑不了 ...