「日常训练」 Mike and Fun (CFR305D2B)
生活随笔
收集整理的這篇文章主要介紹了
「日常训练」 Mike and Fun (CFR305D2B)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意(CodeForces 548B)
每次對01矩陣中的一位取反,問每次操作后,單列中最長連續1的長度。
分析
非常非常簡單,但是我當時訓練的時候WA了四次。。。無力吐槽了,人間 不值得.jpg
代碼
#include <bits/stdc++.h> #define MP make_pair #define PB push_back #define fi first #define se second #define ZERO(x) memset((x), 0, sizeof(x)) #define ALL(x) (x).begin(),(x).end() #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define per(i, a, b) for (int i = (a); i >= (b); --i) #define QUICKIO \ios::sync_with_stdio(false); \cin.tie(0); \cout.tie(0); using namespace std; using ll = long long; using ull = unsigned long long; using pi = pair<int,int>; const int MAXN=500;bool status[MAXN+5][MAXN+5]; int main() { QUICKIOint n,m,k; cin>>n>>m>>k;rep(i,1,n)rep(j,1,m)cin>>status[i][j];int row[MAXN+5]; ZERO(row);rep(i,1,n){int tmp=0;rep(j,1,m){if(status[i][j]){if(j>1 && status[i][j-1])tmp++;else tmp=1;}else{row[i]=max(tmp,row[i]);tmp=0;}}row[i]=max(tmp,row[i]);}rep(i,1,k){int tmp=0;int x,y; cin>>x>>y;status[x][y]=!status[x][y];row[x]=0;rep(j,1,m){if(status[x][j]){if(j>1 && status[x][j-1])tmp++;else tmp=1;}else{row[x]=max(tmp,row[x]);tmp=0;}}row[x]=max(tmp,row[x]);int maxr=0;rep(i,1,n)maxr=max(maxr,row[i]);cout<<maxr<<endl;}return 0; }轉載于:https://www.cnblogs.com/samhx/p/9652066.html
總結
以上是生活随笔為你收集整理的「日常训练」 Mike and Fun (CFR305D2B)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: javascript的数组之reduce
- 下一篇: Day10 Python基础之特殊函数(