假设该矩形是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-1)。

那么,对第一行处理前缀和,Si=S(i-2)^a(1,i),即给出了两个数S的异或,只需将每一个点裂点为i和i’,然后若Si^Sj=0,并查集上连边(i,j)(i’,j’),否则连(i,j’)(i’,j),最后只需判断i和i’是否相连,相连即为0(这个可以理解为i表示i上是1,i’表示i上是0)。

最后,统计出有多少联通块,设有S个,则答案是$2^{(S-4)/2}$(如果没有约束,答案是$2^{n}=2^{2n+4-4)/2$)

 1 #include<bits/stdc++.h>
2 using namespace std;
3 int n,m,x,y,ans,f[200005];
4 char s[11];
5 int find(int k){
6 if (k==f[k])return k;
7 return f[k]=find(f[k]);
8 }
9 void add(int x,int y){
10 if (find(x)!=find(y))f[find(x)]=find(y);
11 }
12 int main(){
13 scanf("%d%d",&n,&m);
14 for(int i=1;i<=2*n+3;i++)f[i]=i;
15 for(int i=1;i<=m;i++){
16 scanf("%d%d%s",&x,&y,s);
17 x-=y;
18 y=min(x+2*y,2*n-x-2*y+2);
19 x=max(x,-x);
20 if (s[0]=='x'){
21 add(2*y,2*x);
22 add(2*y+1,2*x+1);
23 }
24 else{
25 add(2*y+1,2*x);
26 add(2*x+1,2*y);
27 }
28 }
29 for(int i=0;i<=n+1;i++)
30 if (find(2*i)==find(2*i+1)){
31 printf("0");
32 return 0;
33 }
34 int s=0;
35 for(int i=0;i<=2*n+3;i++)s+=(find(i)==i);
36 s=s/2-2;
37 ans=1;
38 for(int i=1;i<=s;i++)ans=ans*2%1000000007;
39 printf("%d",ans);
40 }

[cf461D]Appleman and Complicated Task的更多相关文章

  1. Codeforces 461D. Appleman and Complicated Task 构造,计数

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF461D.html 题解 首先我们可以发现如果确定了第一行,那么方案就唯一了. 然后,我们来看看一个点的值确定 ...

  2. 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 ...

  3. Codeforces 263A. Appleman and Easy Task

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

  4. Codesforces 467E Alex and Complicated Task

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

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

  6. CF461D-Appleman and Complicated Task【并查集】

    正题 题目链接:https://www.luogu.com.cn/problem/CF461D 题目大意 \(n*n\)的网格需要填上\(x\)或\(o\),其中有\(k\)个格子已经固定,求有多少中 ...

  7. Codeforces Round #263

    http://codeforces.com/contest/461 A.水题 B.太挫了,竟然被hack了一发.... C.贪心..竟然没看出来时哈夫曼编码问题 D.题目大意:给一棵树,每一个点为白色 ...

  8. Unity3D游戏在iOS上因为trampolines闪退的原因与解决办法

    http://7dot9.com/?p=444 http://whydoidoit.com/2012/08/20/unity-serializer-mono-and-trampolines/ 确定具体 ...

  9. CF 518 D. Ilya and Escalator

    Ilya got tired of sports programming, left university and got a job in the subway. He was given the ...

随机推荐

  1. ElasticSearch7.X.X-初见-模仿京东搜索的实战

    目录 简介 聊聊Doug Cutting ES&Solr&Lucene ES的安装 安装可视化界面ES head插件 了解ELK 安装Kibana ES核心概念 文档 类型 索引 倒排 ...

  2. VirtualBox上安装Debian10个人备忘笔记

    准备 VirtualBox 下载链接:Downloads – Oracle VM VirtualBox,下载完成后安装即可. Debian 下载链接:通过 HTTP/FTP 下载 Debian CD/ ...

  3. 利用caffe.proto生成caffe.pb.h

    完全按照博文来就好了:http://blog.csdn.net/u012905422/article/details/52794693

  4. Cartography Tools(制图工具)

    制图工具 1.制图优化 # Process: 分散标记 arcpy.DisperseMarkers_cartography("", "", "EXPA ...

  5. 如何做好 NodeJS 框架选型?

    作为一个有一定工作经验的工程师,工作中经常会遇到技术选型的问题.比如当我们在工作中需要使用到 NodeJS 时,第一个要解决的问题就是如何选择一个合适的框架. 不同的框架有不同的特点,如果我们仅仅从框 ...

  6. MySQL8 根据某属性查询字段排名由自定义变量到rank()的变动

    在mysql8 之前的版本,因为没有rank()方法的存在,所以在对字段进行排名时,使用的是自定义自变量的方法,比如: select id,name,@rank=@rank+1 as ranks fr ...

  7. Linux——Docker安装

    1. 安装Docker i :环境准备:Linux要求内核3.0以上 ii:安装 #1.卸载旧版本 yum remove docker \ docker-client \ docker-client- ...

  8. Windows使用Git的vim编辑器编译运行程序

    Windows配置gcc 新建一个main.c $ touch main.c #在当前目录下创建main.c $ mkdir folder #在当前目录下创建folder文件夹 $ rm main.c ...

  9. [对对子队]会议记录4.14(Scrum Meeting 5)

    今天已完成的工作 刘子航 ​ 工作内容:设计第2,3关 ​ 相关issue:设计关卡2,3 吴昭邦 ​ 工作内容:制作场景,暂时解决了坐标错位问题 ​ 相关issue:实现游戏场景中的必要模型 何瑞 ...

  10. zuul过滤器filter 的编写

    通过上一节(zuul的各种配置)的学习,我们学会了zuul路由的各种配置,这一节我们来实现一下zuul的过滤器功能.那么为什么需要用到zuul的过滤器呢?我们知道zuul是我们实现外部系统统一访问的入 ...