原文链接https://www.cnblogs.com/zhouzhendong/p/CF461D.html

题解

首先我们可以发现如果确定了第一行,那么方案就唯一了。

然后,我们来看看一个点的值确定了会导致什么:

假设我们确定了红色点的值,那么所有包含橙色的格子xor起来就等于红色格子的值,绿色蓝色也是。

第一排就比较特殊了。

如果我们在对第一排奇偶分类之后,如果我们可以得到第一行的前缀xor之间的关系,那么我们就有希望解决这个问题。

再看一种情况:

类似地意思,我们会发现这个东西遇到墙会反射。

于是我们就基本可以通过权值并查集来搞定。

我们还剩下一个问题:

这样的方式还不能确定最下面一行是否满足条件。

我们来看一个东西:

通过这个我们可以意识到,第一行和最后一行是一一对应的。于是整个局面旋转180度还是一样的。于是只要第一行合法,那么最后一行也合法。

所以我们只要通过给出的点用权值并查集维护一下第一行,然后算一下答案就好了。

代码

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Fod(i,b,a) for (int i=b;i>=a;i--)
using namespace std;
typedef long long LL;
LL read(){
LL x=0,f=0;
char ch=getchar();
while (!isdigit(ch))
f|=ch=='-',ch=getchar();
while (isdigit(ch))
x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return f?-x:x;
}
const int N=100005,mod=1e9+7;
int n,k;
int fa[N],d[N];
int getf(int x){
if (fa[x]==x)
return x;
int f=getf(fa[x]);
d[x]^=d[fa[x]];
return fa[x]=f;
}
int Pow(int x,int y){
int ans=1;
for (;y;y>>=1,x=(LL)x*x%mod)
if (y&1)
ans=(LL)ans*x%mod;
return ans;
}
int main(){
n=read(),k=read();
For(i,0,n)
fa[i]=i;
while (k--){
int x=read(),y=read(),z;
char s[10];
scanf("%s",s);
z=s[0]=='x'?0:1;
int L=y-(x-1);
if (L<1)
L=1+(1-L);
int R=y+(x-1);
if (R>n)
R=n-(R-n);
L=max(0,L-2);
if (getf(L)!=getf(R))
d[fa[L]]=z^d[L]^d[R],fa[fa[L]]=fa[R];
else if (d[L]^d[R]^z)
return puts("0"),0;
}
int ans=-1;
For(i,0,n)
if (fa[i]==i)
ans++;
if (ans==-1)
assert(0);
cout<<Pow(2,ans)<<endl;
return 0;
}

  

Codeforces 461D. Appleman and Complicated Task 构造,计数的更多相关文章

  1. Codeforces 263A. Appleman and Easy Task

    A. Appleman and Easy Task time limit per test  1 second memory limit per test  256 megabytes input  ...

  2. [cf461D]Appleman and Complicated Task

    假设该矩形是aij,那么有a(i,j)=a(i-1,j-1)^a(i-1,j+1)^a(i-2,j),不断递归下去可以发现a(i,j)=a(1,y-x+1)^a(1,y-x+3)^--^a(1,x+y ...

  3. Codeforces Round #263 (Div. 2) A. Appleman and Easy Task【地图型搜索/判断一个点四周‘o’的个数的奇偶】

    A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...

  4. CodeForces462 A. Appleman and Easy Task

    A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input sta ...

  5. Codeforces 461B Appleman and Tree(木dp)

    题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k ...

  6. Codesforces 467E Alex and Complicated Task

    E. Alex and Complicated Task time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  8. Codeforces 558E A Simple Task(计数排序+线段树优化)

    http://codeforces.com/problemset/problem/558/E Examples input 1 abacdabcda output 1 cbcaaaabdd input ...

  9. Codeforces - 1114B - Yet Another Array Partitioning Task - 构造 - 排序

    https://codeforces.com/contest/1114/problem/B 一开始叫我做,我是不会做的,我没发现这个性质. 其实应该很好想才对,至少要选m个元素,其中m个作为最大值,从 ...

随机推荐

  1. Java大小写转化

    java大写转小写 public String toLowerCase(String str){ char[] chars = str.toCharArray(); for (int i = 0; i ...

  2. Input标签使用整理

    0 写在前面 对于程序而言I/O是一个程序的重要组成部分.程序的输入.输出接口,指定了程序与用户之间的交互方式.对于前端开发而言,input标签也有着其重要地位,它为用户向服务端提交数据提供了可能. ...

  3. jvm学习笔记一(垃圾回收算法)

    一:垃圾回收机制的原因 java中,当没有对象引用指向原先分配给某个对象的内存时候,该内存就成为了垃圾.JVM的一个系统级线程会自动释放该内存块.垃圾回收意味着程序不再需要的对象是"无用信息 ...

  4. 再也不用c++的string了

    今天打比赛,觉得写法没错,但死活过不了大样例.调试时发现用cin读入一行臭长臭长的string类型变量时出锅了,原来几千个字符就读进来500个,导致一直WAWAWAWAWA. 最后yyj神犇帮我就删掉 ...

  5. deepin安装mysql记录

    本文转载自http://www.linuxidc.com/Linux/2016-07/133128.htm sudo apt-get install mysql-server apt-get isnt ...

  6. Vue(小案例_vue+axios仿手机app)_图片列表操作

    一.前言 1.让图片还没有被完全加载出来的时候给用户提示                                       2.图片查看器 二.主要内容 1.让图片还没有被完全加载出来的时候 ...

  7. [APIO2007] 风铃

    题目链接 可能是个树上 DP?指针真好玩 23333. 首先对于所有玩具如果有深度差超过 1 的就是无解(在这里贡献 WA * 3),所以 dfs 一遍记录深度是有必要的…… 然后如果有一个点的两颗子 ...

  8. go 数组 切片 字典 结构体

    数组 ##数组的定义与赋值: 1. var num [3]int num = [3]int{1,2,3} 2. var num [3]int = [3]int {1,2,3} 3. num := [3 ...

  9. Redis学习笔记(三)使用Lua脚本实现分布式锁

    Redis在2.6推出了脚本功能,允许开发者使用Lua语言编写脚本传到Redis中执行. 使用Lua脚本的好处如下: 1.减少网络开销:本来5次网络请求的操作,可以用一个请求完成,原先5次请求的逻辑放 ...

  10. Vorticity directions 1: self-improving property of the vorticity

    在 [Li, Siran. "On Vortex Alignment and Boundedness of $ L^ q $ Norm of Vorticity." arXiv p ...