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. C/C++ string.h头文件小结

    http://note.youdao.com/noteshare?id=cff515f7b683f579d22f17b54b960e2a

  2. mobiscroll 三级联动

    https://demo.mobiscroll.com/jquery/list/treelist#theme=ios官网的代码是要钱的,百度云放了一份

  3. SQL Server 2008自动备份数据库

    1.在电脑开始菜单中选择“SQL Server Management Studio”双击.在出现的界面中点击“连接”按钮. 2.在出现的“ Microsoft SQL Server Managemen ...

  4. LeetCode-Reverse Words in a String[AC源码]

    package com.lw.leet1; import java.util.Stack; /** * @ClassName:Solution * @Description: * Reverse Wo ...

  5. NOIP模拟赛9

    T1U3348 A2-回文数 https://www.luogu.org/problem/show?pid=U3348 考场上钻了牛角尖了,然后0分 #include<cstdio> #i ...

  6. 2D旋转和3D旋转

    2D旋转 先给个容器 <p onClick="rotate2D()" id="rotate2D" class="animated_div&quo ...

  7. 【LibreOJ】#6298. 「CodePlus 2018 3 月赛」华尔兹 BFS

    [题意]给定n*m的网格,起点和终点位置,一些格指定下一步的方向,一些格任意.要求为方向任意的格确定方向,使起点可以走到终点.n,m<=50. [算法]BFS [题解]这道题最好用BFS,因为D ...

  8. sylk文件

    症状:excel表出现提示:sylk文件...导致excel表不可读取 原因:文件内容有“ ID ” 字段,估计是固定的识别“ID”或“ID_XXXX” 修改方法:将ID中的任意字母换成小写即可 转载 ...

  9. defer用途

    package main /* defer :程序退出时执行,先进后执行 defer庸碌: 1.关闭文件句柄 2.锁资源释放 3.数据库连接释放 */ import ( "fmt" ...

  10. Django【设计】同功能不同实现模式的兼容性

    需求: 当我们采集硬件信息时,客户端可以有多种方式,具体方式取决于客户机,CMDB项目中,我们有三种方式可选,AGENT/SSH/SALT,根据客户机具体情况和“SALT>>SSH> ...