原文链接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. 设置QPushbutton按钮背景、鼠标滑过状态、鼠标点击后状态用法

    1.1当要设置QPushbutton按钮背景,字体颜色,鼠标滑过状态,鼠标单击后状态时,可以用QSS来设置,具体的代码如下:     QPushButton *allSelect = new QPus ...

  2. google vimium插件的一些简单命令

    j: 向下滑动 k: 向上滑动 d: 向下一页 u: 向上一页 x: 关闭页面 r: 刷新页面 gg: 回到顶部 yy: 复制网址 t: 打开新标签 f: 显示页内指令 yt: 复制当前网址并打开 o ...

  3. hdu 2829 Lawrence(四边形不等式优化dp)

    T. E. Lawrence was a controversial figure during World War I. He was a British officer who served in ...

  4. jmeter将上一个接口返回值作为下一个接口的请求参数

    在jmeter中有时候会用到,将上一个接口的返回值作为下一个接口的请求参数 具体操作如下: 1.首先新建一个http请求(右键线程组--添加Sampler--http请求),同时添加好接口相应的请求参 ...

  5. jmeter循环控制器加jdbc req结果配合组合参数遍历

    jdbc请求:jdbc sampler  保存结果中三个变量名 循环控制器:xhkzq     的循环次数填写:${其中一个变量名_#} 循环控制器里面:http sampler ,前置处理器,取消c ...

  6. Entity Framework入门教程(12)--- EF进行批量添加/删除

    EF6添加了批量添加/删除实体集合的方法,我们可以使用DbSet.AddRange()方法将实体集合添加到上下文,同时实体集合中的每一个实体的状态都标记为Added,在执行SaveChange()方法 ...

  7. 【原创】支持同时生成多个main函数 makefile 模板

    背景: 去年做项目的时候,由于有需要编译出多个可执行文件的需求,修改了Makefile使其支持生成多个结果(编译多个含有main函数的文件),但总觉得自己的实现不够完美. 今年又遇到这样需求的时候,可 ...

  8. [物理学与PDEs]第5章习题7 各向同性材料时稳定性条件的等价条件

    在线性弹性时, 证明各向同性材料, 稳定性条件 (5. 27) 等价于 Lam\'e 常数满足 $$\bex \mu>0,\quad \lm+\cfrac{2}{3}\mu>0.  \ee ...

  9. luogu P5289 [十二省联考2019]皮配

    传送门 首先考虑一个正常的dp,设\(f_{i,j,k}\)为前\(i\)个学校,\(j\)人在\(\color{#0000FF}{蓝阵营}\),\(k\)人在\(\color{#654321}{吔} ...

  10. safari中input、textarea无法输入的问题

    网址:https://www.cnblogs.com/xiayu25/p/6832748.html * { -webkit-box-sizing: border-box; -moz-box-sizin ...