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的更多相关文章

  1. 【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 ...

  2. 【SRM 717 div2 B】LexmaxReplace

    Problem Statement Alice has a string s of lowercase letters. The string is written on a wall. Alice ...

  3. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  4. 【TP SRM 703 div2 250】AlternatingString

    Problem Statement A string of zeros and ones is called an alternating string if no two adjacent char ...

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

  6. 【cf 483 div2 -C】Finite or not?(数论)

    链接:http://codeforces.com/contest/984/problem/C 题意 三个数p, q, b, 求p/q在b进制下小数点后是否是有限位. 思路 题意转化为是否q|p*b^x ...

  7. 【市场调研与分析】Intel发力移动安全领域——By Me at 20140613

                                                    [市场调研与分析]Intel发力移动安全领域                               ...

  8. 【疯狂造轮子-iOS】JSON转Model系列之二

    [疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...

  9. 【疯狂造轮子-iOS】JSON转Model系列之一

    [疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...

随机推荐

  1. activity的23张表

    --二进制数据表 SELECT * FROM act_ge_bytearray; --属性数据表存储整个流程引擎级别的数据,初始化表结构时,会默认插入三条记录, SELECT * FROM act_g ...

  2. LCD段码驱动

    假如要第3个数码关显示“8.”,则3A-3D均得为1,即Seg3和Seg4均得为1.假设模具Seg和驱动芯片Seg对应,则只需往HT1621的地址Seg3和Seg4分半发送0xF. 注意:HT1621 ...

  3. windows2008 虚拟机64位的操作系统安装32位的应用程序

    64位的操作系统安装32位的应用程序: 安装成功但是使用有问题 报错: 最终解决: 在一台物理机的win7上面安装该软件. 然后把安装好的文件全部拷贝到win2008虚拟机上面 启动,使用 多ok了! ...

  4. php查询字符串是否存在 strpos

    /*** 查询字符是否存在于某字符串** @param $haystack 字符串* @param $needle 要查找的字符* @return bool*/function str_exists( ...

  5. socket网络编程登录实现及多客户端和服务端的数据交互

    一.TCP/IP 客户端 package com.demo.entity; import java.io.Serializable; public class UserInfo implements ...

  6. 算法38---292. Nim游戏

    1.题目: 你和你的朋友,两个人一起玩 Nim游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解. 编写一个函 ...

  7. ansible搭建mysql主主模式

    ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)等优点,实现了批量系统配置.批量程序部署.批量运行命 ...

  8. C指针思考-(1)

    首先记录下时间吧,@2016-08-18 23:26:22,这段时间看了同事的3本经典的书,<c缺陷和陷阱>,<c和指针>和<c专家编程>,感觉指针说的最多,多多少 ...

  9. Zabbix分布式配置

    Zabbix是一个分布式监控系统,它可以以一个中心点.多个分节点的模式运行,使用Proxy能大大的降低Zabbix Server的压力,Zabbix Proxy可以运行在独立的服务器上,安装Zabbi ...

  10. 什么是面向对象以及其意义,prototpye原型

    什么是面向对象: 使用对象时,只关注对象提供的功能,不关注其内部的细节 例如:jquery 什么是对象: 对象是一个整体对外提供一些操作,比如 收音机 面向对象编程OOP的特点: 1.抽象:把主要的特 ...