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 ...
随机推荐
- 调用百度API进行文本纠错
毕设做的是文本纠错方面,然后今天进组见研究生导师 .老师对我做的东西蛮感兴趣.然后介绍自己现在做的一些项目,其中有个模块需要有用到文本纠错功能. 要求1:有多人同时在线编辑文档,然后文档功能有类似Wo ...
- MyBatis-Plus 使用说明介绍
先看一下和MyBatis 不同点说明: @GetMapping("/select_sql") public Object getUserBySql() { User user=ne ...
- 单调栈&单调队列
最近打了三场比赛疯狂碰到单调栈和单调队列的题目,第一,二两场每场各一个单调栈,第三场就碰到单调队列了.于是乎就查各种博客,找单调栈,单调队列的模板题去做,搞着搞着发现其实这两个其实是一回事,只不过利用 ...
- Spring AOP 面向切面的Spring
定义AOP术语 描述切面的常用术语有: 通知 (advice) 切点 (pointcut) 连接点 (joinpoint) 下图展示了这些概念是如何关联的 Spring 对AOP的支持 Spring提 ...
- 19个心得,明明白白说Linux下的负载均衡
一.目前网站架构一般分成负载均衡层.web层和数据库层,我其实一般还会多加一层,即文件服务器层,因为现在随着网站的PV越来越多,文件服务器的压力也越来越大;不过随着moosefs.DRDB+Heart ...
- memcached.c 源码分析
上文分析了memcached的autoconf过程以及configure, make过程,可以看到,memcached可执行文件是由memcached-memcached.o以及其他文件连接后编译出来 ...
- Unity基于NGUI的简单并可直接使用的虚拟摇杆实现(一)
可能大家都听说过大名鼎鼎的easytouch,然而easytouch是基于UGUI的,两种不同的UI混用,可能会造成项目管理的混乱,并且可能会出现各种幺蛾子,比如事件传递互相扰乱的问题. 于是就想找一 ...
- 前端本地proxy跨域代理配置
等了好久的接口,总算拿到了,结果却发现用本地localhost:9712去请求接口的时候,出现了跨域错误,而这个时候我们就需要进行下跨域配置了. 首先,找到项目中名为webpack.config.js ...
- Button 使用详解
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...
- 01-Spring Security框架学习
目录 01-Spring Security框架学习 简介 Spring Security 是什么 Spring Security 解决那些问题 Spring Security 的优点 历史背景 Spr ...