Codeforces 461D. Appleman and Complicated Task 构造,计数
原文链接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 构造,计数的更多相关文章
- Codeforces 263A. Appleman and Easy Task
A. Appleman and Easy Task time limit per test 1 second memory limit per test 256 megabytes input ...
- [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 ...
- 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 ...
- 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 ...
- Codeforces 461B Appleman and Tree(木dp)
题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k ...
- Codesforces 467E Alex and Complicated Task
E. Alex and Complicated Task time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- Codeforces 558E A Simple Task(计数排序+线段树优化)
http://codeforces.com/problemset/problem/558/E Examples input 1 abacdabcda output 1 cbcaaaabdd input ...
- Codeforces - 1114B - Yet Another Array Partitioning Task - 构造 - 排序
https://codeforces.com/contest/1114/problem/B 一开始叫我做,我是不会做的,我没发现这个性质. 其实应该很好想才对,至少要选m个元素,其中m个作为最大值,从 ...
随机推荐
- MySQL数据目录(data)迁移
因为系统分区的空间不足,添加了一块硬盘,挂载到/data目录下,把MySQL的数据目录(data)迁移过去. 1.停止MySQL服务: [root@zabbix mysql]# service mys ...
- WEB-INF 目录
WEB-INF 目录是必须的,其中包括: web.xml 文件,该 Web 基本配置,必须. classes 目录,存放 .class 文件,当然也可以将 .java 文件一并放进去. lib 目录, ...
- 工作任务: 批量处理wav音频文件--shell脚本
#!/bin/bash # 处理音频 deal_with_wav() { ) do ) do # gd1_music ./tool/fixbeam2 -c res/fixbeam2.bin -b -i ...
- free命令查看内存信息
free介绍 FREE(1) Linux User’s Manual FREE(1) NAME free - Display amount of free and used memory in the ...
- [Tex学习笔记]小于等于一个常数乘以...
偏微分的论文中常用: 小于等于一个常数乘以... 这个要怎么输入呢. 只要输入\lesssim 就能得到 $\lesssim$...哈哈. 以前知道, 但是忘记了. 现在又要用.
- [再寄小读者之数学篇](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}^{ ...
- [物理学与PDEs]第2章第2节 粘性流体力学方程组 2.5 粘性热传导流体动力学方程组的数学结构
1. 粘性热传导流体动力学方程组可化为 $$\beex \bea \cfrac{\p \rho}{\p t}&+({\bf u}\cdot\n)\rho=-\rho \Div{\bf u}, ...
- EffectiveC++ 第4章 设计与声明
我根据自己的理解,对原文的精华部分进行了提炼,并在一些难以理解的地方加上了自己的"可能比较准确"的「翻译」. Chapter4 设计与声明 Designs and Declarat ...
- idea+maven+ssm搭建boot_crm项目遇到的问题
使用idea+maven+ssm搭建一个boot_crm项目,遇到的问题如下: 1.环境搭建好了,相关配置文件都配置好了,也部署到了tomcat,但是无法启动首页. 通过百度,google找到了,原因 ...
- UOJ #109「APIO2013」TASKSAUTHOR
貌似是最入门的题答题 刚好我就是入门选手 就这样吧 UOJ #109 题意 太热了不讲了 $ Solution$ 第一个点:$ 105$个数字卡掉$ Floyd$ 直接$101$个点无出边一次询问就好 ...