CodeForces 548B 模拟连续的技巧。
2017-08-19 09:31
302 查看
题目比较水,可是我在比赛时候没有AC,很难过。
AC代码:
注意他统计连续的1的技巧,不需要n^3,n^2即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
const int maxn=5e2+10;
const int inf=0x3f3f3f3f;
bool bears[maxn][maxn];
int ans[maxn];
int main()
{
int n,m,q;
while(scanf("%d%d%d",&n,&m,&q)==3)
{
memset(ans,0,sizeof(ans));
memset(bears,0,sizeof(bears));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&bears[i][j]);
for(int i=1;i<=n;i++)
{
int cnt=0;
for(int j=1;j<=m;j++)
{
if(bears[i][j]) cnt++;
else cnt=0;
ans[i]=max(ans[i],cnt);
}
}
for(int i=1;i<=q;i++)
{
int t1,t2;
scanf("%d%d",&t1,&t2);
bears[t1][t2]=!bears[t1][t2];
int cnt=0;
int maxxx=-1;
for(int j=1;j<=m;j++)
{
if(bears[t1][j]) cnt++;
else cnt=0;
maxxx=max(cnt,maxxx);
}
ans[t1]=maxxx;
int maxx=-1;
for(int j=1;j<=n;j++)
if(maxx<ans[j])
maxx=ans[j];
printf("%d\n",maxx);
}
}
}
AC代码:
注意他统计连续的1的技巧,不需要n^3,n^2即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
const int maxn=5e2+10;
const int inf=0x3f3f3f3f;
bool bears[maxn][maxn];
int ans[maxn];
int main()
{
int n,m,q;
while(scanf("%d%d%d",&n,&m,&q)==3)
{
memset(ans,0,sizeof(ans));
memset(bears,0,sizeof(bears));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&bears[i][j]);
for(int i=1;i<=n;i++)
{
int cnt=0;
for(int j=1;j<=m;j++)
{
if(bears[i][j]) cnt++;
else cnt=0;
ans[i]=max(ans[i],cnt);
}
}
for(int i=1;i<=q;i++)
{
int t1,t2;
scanf("%d%d",&t1,&t2);
bears[t1][t2]=!bears[t1][t2];
int cnt=0;
int maxxx=-1;
for(int j=1;j<=m;j++)
{
if(bears[t1][j]) cnt++;
else cnt=0;
maxxx=max(cnt,maxxx);
}
ans[t1]=maxxx;
int maxx=-1;
for(int j=1;j<=n;j++)
if(maxx<ans[j])
maxx=ans[j];
printf("%d\n",maxx);
}
}
}
相关文章推荐
- codeforces 5C Longest Regular Bracket Sequence(dp+技巧)【最长连续括号模板】
- codeforces-869B(模拟&技巧)
- CodeForces - 630M Turn (模拟&技巧) 水
- Codeforces--658C--Bear and Forgotten Tree 3(模拟&&技巧)(好题)
- CodeForces 550A Two Substrings(模拟)
- codeforces 899 E - Segments Removal(链表模拟)
- CodeForces - 246A Buggy Sorting (模拟)水
- ZOJ - 3872 Beauty of Array (技巧&模拟)好题
- codeforces 279C Ladder(数据技巧)
- 【CodeForces - 758C Unfair Poll】 暴力 + 模拟
- 在Java中模拟多重继承--扩展多个类的技巧
- Codeforces_387A_George and Sleep(模拟)
- CodeForces 350C Bombs(模拟)
- 【模拟】Codeforces 705B Spider Man
- 【CodeForces 333A】Secrets(模拟)
- CodeForces - 597A Divisibility (模拟)
- 【模拟】Codeforces 710C Magic Odd Square
- 【WPF实用技巧】Blend创建模拟(示例)数据
- 伪知识之通俗易懂得解析selenium常用模拟登陆技巧持续更新:【内向即废物--沈吟秋】
- CodeForces - 808E-K - Selling Souvenirs-DP(像背包但不是背包)+优化技巧