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 ...
随机推荐
- mysql group_concat方法用法
目前有三张表: 课程表: course,里面有student_id 学生表: student,里面有 name 字段 中间表(课程和学生一对多): course_student, 里面有 co ...
- 我学习的第一个uiautomator从创建到运行结束
一.新建自动化脚本 1.新建java工程包 [file]----[new]----[Java Project] 新建工程 [右 ...
- 平衡树【Treap】
平衡树的板题,用Treap实现. 具体参见注释,写的很详细了,包括了原理,实现以及注意事项 蒟蒻写个注释板子写了两天,太弱了QAQ 感谢niiick指导 Code #include<iostre ...
- KeyDown,KeyPress和KeyUp详解(转)
1.按键的类型 Windows窗体将键盘输入标识为由按位Keys枚举表示的虚拟键代码.使用Keys枚举,可以综合一系列按键以生成单个值,这些值与WM_KEYDOWN和WM_SYSKEYDOWNWind ...
- uva 1636 Headshot
https://vjudge.net/problem/UVA-1636 首先在手枪里随机装一些子弹,然后抠了一枪,发现没有子弹.你希望下一枪也没有子弹,是应该直接再抠一枪(输出SHOOT)呢,还是随机 ...
- 贪心+离散化+线段树上二分。。。 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest G. Of Zorcs and Axes
题目链接:http://codeforces.com/gym/101149/problem/G 题目大意:给你n对数字,为(a[i], b[i]),给你m对数字,为(w[i], c[i]).给n对数字 ...
- dfs序+主席树 BZOJ 2588 当然树链剖分+主席树也可以?
2588: Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 5822 Solved: 1389 ...
- CF766 ABCDE
LINK A 找最长非公共子序列..如果两串不是完全相同 显然就是最长的那个 /** @Date : 2017-04-15 19:52:34 * @FileName: 766A.cpp * @Plat ...
- 【Java-GUI】homework~QQ登录界面
话说有图有真相:(图片文件自己ps吧,动态网页未添加成功,后附html源码) Java源码: import javax.swing.*; import java.awt.*; import java. ...
- 关于aspx.designer.cs的研究
.aspx文件..aspx.cs文件和.aspx.designer.cs的一些说明 .aspx文件:(页面)书写页面代码.存储的是页面design代码.只是放各个控件的代码,处理代码一般放在.cs文件 ...