CF#305-B. Mike and Fun-暴力模拟水题
来源:互联网 发布:2017年新出的网络剧 编辑:程序博客网 时间:2024/04/30 13:35
http://codeforces.com/contest/548/problem/B
题意:
给出n*m的01矩阵,给一个q,表示q次操作
操作 给出【i,j】,表示对 矩阵的i行k列的元素取反
每次操作后 给出 n行中, 最连续1的个数。
用一个ans【n】数组维护每一行的最多连续的1就好
n只有500,每次取反操作后,直接遍历把当前行更新后的最多连续的1记录到ans[i]
然后for(i=1:n) 遍历取一个最大的ans[i]
复杂度 q*o(n)
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <queue>#include <map>#include <set>#include <vector>using namespace std;int tm[505][505];int ans[505]; //i-th row's max continous 1int main(){ int n,m,q; int i,j; scanf("%d%d%d",&n,&m,&q); for (i=1;i<=n;i++) { for (j=1;j<=m;j++) { scanf("%d",&tm[i][j]); } } int tmp,maxx; for (i=1;i<=n;i++) //pre_ { tmp=0; maxx=0; for (j=1;j<=m;j++) { if (tmp>maxx) maxx=tmp; if (j==1) tmp=tm[i][j]; else if (tm[i][j]==1) { if (tm[i][j-1]==1) tmp++; else tmp=1; } else tmp=0; } if (tmp>maxx) maxx=tmp; ans[i]=maxx; } int a,b; for (i=1;i<=q;i++) { scanf("%d%d",&a,&b); tm[a][b]=!tm[a][b]; ///*************update tmp=0; maxx=0; for (j=1;j<=m;j++) { if (tmp>maxx) maxx=tmp; if (j==1) tmp=tm[a][j]; else if (tm[a][j]==1) { if (tm[a][j-1]==1) tmp++; else tmp=1; } else tmp=0; } if (tmp>maxx) maxx=tmp; ans[a]=maxx; maxx=0; for (j=1;j<=n;j++) { if (ans[j]>maxx) maxx=ans[j]; } printf("%d\n",maxx); //**************** } return 0;}
0 0
- CF#305-B. Mike and Fun-暴力模拟水题
- B. Mike and Fun
- B. Mike and Fun
- CodeForces - 548B Mike and Fun (模拟)
- Codeforces Round #305 (Div. 2) B.Mike and Fun
- Codeforces Round #305 (Div. 2) B. Mike and Fun(水题)
- Codeforces Round #305 (Div. 2)B. Mike and Fun
- Codeforces Round #305 (Div. 2) C. Mike and Frog +B. Mike and Fun
- Codeforces548B Mike and Fun (模拟)
- CodeForces 548B Mike and Fun
- CodeForces 548B Mike and Fun
- 【codeforces 548B】Mike and Fun
- Codeforces Round #305 (Div. 2)-Mike and Fun(暴力求解连续1)
- Mike and Feet(CF 547B)
- 【数据结构】 CF 547B Mike and Feet
- B. Mike and Shortcuts(cf#361)
- codeforces B. Mike and strings 暴力+字符串
- Codeforces548B:Mike and Fun
- 17.1.2.2 Usage of Row-Based Logging and Replication
- C++ Template 实践草稿(two)
- view的三个构造方法与findViewById()结果为null的关系?
- C程序内存分配
- sqlserver 查询生成XML格式数据
- CF#305-B. Mike and Fun-暴力模拟水题
- Lua基本语法介绍
- 如何将decimal转换为dbnull
- 冒泡排序代码详解
- 第4周 项目3-单链表应用(3)
- 第6周项目5-后缀表达式
- ArrayUtils工具类
- 浅谈 PHP 与手机 APP 开发(API 接口开发)
- 第4周实践项目1-- 建立单链表