Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp
思路:分块dp, 对于修改将对应的块再dp一次。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg
using namespace std; const int N = 1e5 + ;
const int M = 1e7 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
int n, m, q, block[N], L[N], R[N];
char s[N][], op[];
PII f[N][]; PII dp(int x, int y, char c, int B) {
if(x == L[B] - || y == || y == m + ) return mk(x, y);
if(f[x][y].fi || f[x][y].se) return f[x][y];
if(s[x][y] == '>' && c == '<') return f[x][y] = mk(-, -);
if(s[x][y] == '<' && c == '>') return f[x][y] = mk(-, -);
if(s[x][y] == '>') return f[x][y] = dp(x, y + , s[x][y], B);
if(s[x][y] == '<') return f[x][y] = dp(x, y - , s[x][y], B);
return f[x][y] = dp(x - , y, s[x][y], B);
} void update(int B) {
for(int i = L[B]; i <= R[B]; i++)
for(int j = ; j <= m; j++)
dp(i, j, '^', B);
} int main() {
memset(L, -, sizeof(L));
memset(R, -, sizeof(R)); scanf("%d%d%d", &n, &m, &q); for(int i = ; i <= n; i++) {
block[i] = i / ;
if(L[block[i]] == -) L[block[i]] = i;
R[block[i]] = i;
} for(int i = ; i <= n; i++) {
scanf("%s", s[i] + );
} for(int i = ; i <= n / ; i++) update(i); while(q--) {
int x, y;
scanf("%s%d%d", op, &x, &y);
if(op[] == 'C') {
scanf("%s", op);
s[x][y] = op[];
int p = x / ;
for(int i = L[p]; i <= R[p]; i++)
memset(f[i], , sizeof(f[i]));
update(p); } else {
while((x != -) && (x >= && x <= n && y >= && y <= m)) {
int ntx = f[x][y].fi;
int nty = f[x][y].se;
x = ntx;
y = nty;
}
printf("%d %d\n", x, y);
}
}
return ;
} /*
*/
Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp的更多相关文章
- Codeforces Round #278 (Div. 1) B. Strip multiset维护DP
B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #278 (Div. 2)
题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...
- Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)
B. Candy Boxes Problem's Link: http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...
- Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力
A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...
- CodeForces Round #278 (Div.2) (待续)
A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...
- Codeforces Round #278 (Div. 1)
A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...
- codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)
题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...
- Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp
D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
随机推荐
- HTTP ------ connection 为 close 和 keep-alive 的区别
keep-alive和close这个要从TCP握手讲起 HTTP请求是基于TCP连接的,TCP的请求会包含(三次握手,中间请求,四次挥手)在HTTP/1.0时代,一个HTTP请求就要三次握手和四次挥手 ...
- LINUX安全加固操作
1.禁止Ctrl-Alt-Delete组合键重启系统 vi /etc/inittab #ca::ctrlaltdel:/sbin/shutdown -t3 -r now 如果还存在下面的文件,则需要注 ...
- animatescroll.min.js ~~~~ jq滚动效果 优化target自定义方法
$(".meun>div[name='meun_nav']>a").eq(1).on("click",function(){ $("bod ...
- [DeeplearningAI笔记]序列模型3.3集束搜索
5.3序列模型与注意力机制 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.3 集束搜索Beam Search 对于机器翻译来说,给定输入的句子,会返回一个随机的英语翻译结果,但是你想要一 ...
- codevs 1029 遍历问题
1029 遍历问题 http://codevs.cn/problem/1029/ 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 我们都很熟悉二叉树的 ...
- bash高级
重定向 管道: ps -ef | grep bash 管道作为命令衔接的 两个都写 ,一个到文件,一个到屏幕 tee null
- [ERROR] Too many connections 尚未解决
[ERROR] - com.alibaba.druid.support.logging.Log4j2Impl.error(Log4j2Impl.java:53) - create connection ...
- Java 中的几种线程池这么用才是对的
为什么要使用线程池 虽然大家应该都已经很清楚了,但还是说一下.其实归根结底最主要的一个原因就是为了提高性能. 线程池和数据库连接池是同样的道理,数据库连接池是为了减少连接建立和释放带来的性能开销.而线 ...
- 【leetcode 简单】第三题 回文数
判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...
- Ubuntu 下 CodeBlocks 修改用户自定义颜色主题 及 更新CodeBlocks到最新版本
Code::Blocks默认的白色编辑器界面看久了眼睛很累, 所以想换成dark的主题, 眼睛会舒服些. 1. 安装好codeblocks后, 先运行一次, 关闭, 这时程序会提示你是否要保存defa ...