原文链接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. StringUtils常用方法+StringUtils详细介绍

    StringUtils常用方法+StringUtils详细介绍   StringUtils用法+StringUtils详细介绍博文来源:http://yijianfengvip.blog.163.co ...

  2. 关于win10企业版在极域电子教室软件 v4.0 2015 豪华版的全屏控制下如何取得自由

    注.可能因为系统和软件的缘故无法实现 背景 由于在听课过程过于自闭,于是想自己去网上搜点东西看下 于是 经过了一番乱搞 逐渐摸索出了现方法. 方案1: 大力出奇迹 由于电脑在刚刚进入的状态的时候有段时 ...

  3. 【洛谷P3605】晋升者计数

    题目大意:给定一棵 N 个点的树,点有点权,求对于每个点来说,以该点为根的子树内比该点点权小的点的个数. 题解:考虑对于每个点开一棵权值线段树.递归过程中,将子树的信息合并到父节点上,统计答案后,再将 ...

  4. linux下串口函数

    tcgetattr(), tcsetattr(), tcdrain(),tcflush(), tcflow(), tcsendbreak(),cfmakeraw(), cfgetispeed(),cf ...

  5. linux系统无法启动或无法登入

    修改root权限: https://blog.csdn.net/houjue2298/article/details/78539827 修改密码: https://www.cnblogs.com/we ...

  6. 机器学习 - 损失计算-softmax_cross_entropy_with_logits

    tf.nn.softmax_cross_entropy_with_logits(logits, labels, name=None) 第一个参数logits:就是神经网络最后一层的输出 第二个参数la ...

  7. MongoDB实战性能优化

    1. 性能优化分类 mongodb性能优化分为软件层面和操作系统层面. 软件层面,一般通过修改mongodb软件配置参数来达到,这个需要非常熟悉mongodb里面的各种配置参数: 而操作系统层面,相对 ...

  8. django - 总结 - CRM - 知识点

    1.扩展auth_user from django.contrib.auth.models import User,AbstractUser class UserInfo(AbstractUser): ...

  9. [再寄小读者之数学篇](2014-05-28 Ladyzhenskaya 不等式)

    $$\bex f\in C_c^\infty(\bbR^2)\ra \sen{f}_{L^4}\leq \sqrt{2} \sen{f}_{L^2}^{1/2} \sen{\p_1f}_{L^2}^{ ...

  10. 设计模式五: 原型模式(Prototype)

    简介 原型模式是属于创建型模式的一种,是通过拷贝原型对象来创建新的对象. 万能的Java超类Object提供了clone()方法来实现对象的拷贝. 可以在以下场景中使用原型模式: 构造函数创建对象成本 ...