D - Conveyor Belts

思路:分块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的更多相关文章

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

  2. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  3. Codeforces Round #278 (Div. 2)

    题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...

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

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

  6. CodeForces Round #278 (Div.2) (待续)

    A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...

  7. Codeforces Round #278 (Div. 1)

    A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...

  8. codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)

    题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...

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

随机推荐

  1. [python]乱码:python抓取脚本

    参考: http://www.zhxl.me/1409.html 使用 python urllib2 抓取网页时出现乱码的解决方案 发表回复 这里记录的是一个门外汉解决使用 urllib2 抓取网页时 ...

  2. python如何优雅判断类型

    http://note.youdao.com/noteshare?id=6f3a7963efc57b5d0b1c712654d100c6

  3. win32/linux 线程 log

    原文 #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef WIN32 #includ ...

  4. proc文件系统介绍

    (1)linux内核是一个非常庞大.非常复杂的一个单独的程序,对于这样的一个程序来说调试是非常复杂的.(2)项kernel这样庞大的项目,给里面添加/更改一个功能是非常麻烦的,因为你这添加的一个功能可 ...

  5. SSH免密码登录,实现数据传输备份

    简单来说,就是通过ssh-keygen -t rsa命令来产生一组公私钥,私钥是id_rsa,公钥是id_rsa.pub,把公钥上传到另一台服务器对应账号的.ssh/authorized_keys,即 ...

  6. uva 11722 Joining with Friend

    https://vjudge.net/problem/UVA-11722 题意:你和朋友都要乘坐火车,并且都会途径A城市.你们很想会面,但是你们到达这个城市的准确时刻都无法确定.你会在时间区间[t1, ...

  7. 《JavaScript 实战》:JavaScript 实现图片切割效果

    很久之前就在一个网站的截取相片的功能中看到这个效果,也叫图片裁剪.图片剪切(设置一下也可以做出放大镜等类似的效果).当时觉得很神奇,碍于水平有限,没做出来.前些日子突然想做一个透镜效果,就突然想到了这 ...

  8. TED_Topic2:My desperate journey with a human smuggler

    My desperate journey with a human smuggler By Barat Ali Batoor When I was a child there was a toy wh ...

  9. NYOJ 141 Squares (数学)

    题目链接 描述 A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-degre ...

  10. C - Contest Setting Gym - 101982C dp 补题

    题目链接:https://vjudge.net/contest/273260#problem/C 学习了一下别人的思路,首先去重,然后离散化. dp数组开二维,每一次更新,状态转移方程,dp[ i ] ...