Codeforces 1006F
题意略。
思路:
双向bfs。

如图,对于曼哈顿距离为5的地方来说,除去两端的位置,其他位置的状态不会超过曼哈顿距离为4的地方的状态的两倍。
所以,最大曼哈顿距离为n + m。最多的状态不过2 ^ (n + m)。
这个复杂度我们不能接受,但是如果我们从两边向中间bfs的话, 每次bfs的复杂度为2 ^ ((n + m)/2)。
所以可以用双向广搜来解决。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ; struct point{
int x,y;
LL state;
point(int a = ,int b = ){
x = a,y = b;
}
point operator+ (const point& p){
return point(x + p.x,y + p.y);
}
int sum(){
return x + y;
}
bool operator< (const point& p) const{
if(x != p.x) return x < p.x;
else if(y != p.y) return y < p.y;
else return state < p.state;
}
}; point mov1[] = {point(,),point(,)};
point mov2[] = {point(-,),point(,-)}; LL board[maxn][maxn];
LL n,m,k;
map<point,LL> mp; void bfs1(point s){
int line = ((n + m)>>) + ;
s.state = board[s.x][s.y];
queue<point> que;
que.push(s);
while(que.size()){
point temp = que.front();
que.pop();
if(temp.sum() == line){
++mp[temp];
continue;
}
for(int i = ;i < ;++i){
point nxt = temp + mov1[i];
if(nxt.x > n || nxt.y > m) continue;
nxt.state = temp.state xor board[nxt.x][nxt.y];
que.push(nxt);
}
}
}
LL bfs2(point s){
LL ret = ;
int line = ((n + m)>>) + ;
s.state = k xor board[s.x][s.y];
queue<point> que;
que.push(s);
while(que.size()){
point temp = que.front();
que.pop();
if(temp.sum() == line){
ret += mp[temp];
continue;
}
for(int i = ;i < ;++i){
point nxt = temp + mov2[i];
if(nxt.x < || nxt.y < ) continue;
nxt.state = temp.state xor board[nxt.x][nxt.y];
que.push(nxt);
}
}
return ret;
} int main(){
scanf("%lld%lld%lld",&n,&m,&k);
for(int i = ;i <= n;++i){
for(int j = ;j <= m;++j){
scanf("%lld",&board[i][j]);
}
}
bfs1(point(,));
int line = ((n + m)>>) + ;
for(int i = ;i <= n;++i){
int j = line - i;
if(j <= ) continue;
board[i][j] = ;
}
LL ans = bfs2(point(n,m));
printf("%lld\n",ans);
return ;
}
Codeforces 1006F的更多相关文章
- [CodeForces]1006F Xor Path
双向搜索. 水div3的时候最后一道题由于C题死活看不懂题 来不及做F了Orz.. 因为n,m是20,双向搜索一下,求个到中间的Xor值的方案,统计一下即可. 时间复杂度\(O(2^{21})\) 好 ...
- CodeForces - 1006F (深搜从两端向中间搜,省时)
题意:输入n,m,k,给出一个n*m的图,里面有权值,从1,1一路异或到n,m,只能向右或向下走,等于k有多少种路径. 思路:一开始就是直接暴力写个深搜,稳稳的超时,分析一下时间复杂度.每个点有两个方 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- @GetMapping、@PostMapping和@RequestMapping的区别
@GetMapping 用于将Http Get 请求映射到特定处理程序方法的注释.具体来说就是:@GetMapping是一个作为快捷方式的组合注释 @RequestMapping(method = R ...
- 《Scalable IO in Java》译文
<Scalable IO in Java> 是java.util.concurrent包的作者,大师Doug Lea关于分析与构建可伸缩的高性能IO服务的一篇经典文章,在文章中Doug L ...
- 287. 寻找重复数 Java解法
287. 寻找重复数 这题的难点就在于下面的说明了,我们先不管下面的那些说明的要求,用常规的解法来解答下上的题目. 排序思想解法 先把原来的数组进行排序,然后逐个遍历,一旦发现后一个元素和当前的元素相 ...
- bean的创建(五)第二部分 寻找bean的工厂方法实例化
instanceWrapper = createBeanInstance(beanName, mbd, args); AbstractAutowireCapableBeanFactory.create ...
- VIM常用命令速查(转)
- 「玩转Python」打造十万博文爬虫篇
前言 这里以爬取博客园文章为例,仅供学习参考,某些AD满天飞的网站太浪费爬虫的感情了. 爬取 使用 BeautifulSoup 获取博文 通过 html2text 将 Html 转 Markdown ...
- Spring 核心技术(5)
接上篇:Spring 核心技术(4) version 5.1.8.RELEASE 1.4.5 自动装配协作者 Spring 容器可以自动连接协作 bean 之间的关系.你可以让 Spring 通过检查 ...
- 华为路由交换综合实验 ---IA阶段
目录 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 根据拓扑合理规划IP地址以及VLANIf地址(PC1属于运营部,PC2属于市场 ...
- poj 1455 Crazy tea party
这道题第一眼看去很难,其实不然,短短几行代码就搞定了. 说一下大概思路,如果是排成一排的n个人,如 1 2 3 4 5 6 7 8 我们要变成 8 7 6 5 4 3 2 1 需要交换 28次,找规律 ...
- 4. 源码分析---SOFARPC服务端暴露
服务端的示例 我们首先贴上我们的服务端的示例: public static void main(String[] args) { ServerConfig serverConfig = new Ser ...