↓ Skip to main content
  1. Posts/

codeforces 548B Mike and Fun

·443 words·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://codeforces.com/problemset/problem/548/B

比赛的时候不懂为什么就没做出来…. 其实很容易想到一个o(q*(n+m))的做法… 就是每次更新,要同时更新当前更新行的最大连续和….O(m)可以完成…然后在O(n)扫一遍,找到所有行中的最大值。 然后需要注意的是,在第一次更改之前就要把每个行的最大值处理出来l.. 然后cf机器真是够快,O(nmq)的1.2S过。。。。

代码实现
 1
 2
 3
 4
 5
 6
 7
 8    /* ***********************************************
 9    Author :111qqz
10    Created Time :2016年02月19日 星期五 17时01分58秒
11    File Name :code/cf/problem/548B.cpp
12    ************************************************ */
13
14    #include <algorithm>
15    #include <cstdio>
16    #include <iostream>
17    #include <cstring>
18    #include <string>
19    #include <cmath>
20    #include <map>
21
22    using namespace std;
23    const int N=5E2+5;
24    int a[N][N];
25    int fans;
26    int n,m,q,x,y,cur,ans[N];
27    int main()
28    {
29        cin>>n>>m>>q;
30        for (int i = 1 ; i <= n;i++ )
31        {
32            for (int j = 1; j <= m ; j++ )
33                    scanf("%d",&a[i][j]);
34            cur = 0;
35            for (int j = 1; j <=m ;j++ )
36                if (a[i][j]==1)
37                {
38                    cur++;
39                    ans[i]=max(cur,ans[i]);
40                }
41                else
42                {
43                   cur = 0;
44                }
45        }
46        for ( int i = 1 ; i <= q; i++ )
47        {
48            scanf("%d %d",&x,&y);
49            a[x][y]=a[x][y]^1;
50           // if (i==3) cout<<a[x][y]<<"sadsadasd"<<endl;
51            cur = 0;
52            ans[x]=0;
53            for (int j = 1; j <=m ;j++ )
54                if (a[x][j]==1)
55                {
56                    cur++;
57                    ans[x]=max(cur,ans[x]);
58                }
59                else
60                {
61                   cur = 0;
62                }
63            fans=-1;
64            for (int j = 1;j <= n ; j++ )
65                if (ans[j]>fans)
66                {
67                    fans=ans[j];
68                }
69            cout<<fans<<endl;
70        }
71
72
73        return 0;
74    }

Related

codeforces 548 A. Mike and Fax

·234 words·1 min
http://codeforces.com/problemset/problem/548/A 水题。分割成K个,每个串判断是否回文,如果都是就yes,否则no 需要注意的是,可能不能正好分成长度相同的K个,这个时候也要No 代码实现 1 2 3 4 5 /* *********************************************** 6 Author :111qqz 7 Created Time :2016年03月03日 星期四 14时09分08秒 8 File Name :code/cf/problem/548A.cpp 9 ************************************************ */ 10 11 #include <algorithm> 12 #include <cstdio> 13 #include <iostream> 14 #include <cstring> 15 #include <string> 16 #include <cmath> 17 #include <map> 18 19 using namespace std; 20 const int N=1E3+5; 21 char st[N]; 22 int k,len,ave; 23 bool ok(int l,int r) 24 { 25 for (int i = l ; i<=(l+r)/2;i++) 26 if (st[i]!=st[l+r-i]) 27 return false; 28 return true; 29 } 30 31 int main() 32 { 33 cin>>st; 34 cin>>k; 35 len = strlen(st); 36 ave= len/k; 37 if (k*ave!=len){cout<<"NO"<<endl;return 0;} 38 for (int i = 1 ; i<=k;i++ ) 39 { 40 if (!ok((i-1)*ave,i*ave-1)) 41 { 42 cout<<"NO"<<endl; 43 //cout<<i<<endl; 44 return 0; 45 } 46 47 } 48 cout<<"YES"<<endl; 49 50 51 52 return 0; 53 }

poj 2492 A Bug's Life (并查集)

·402 words·1 min
http://poj.org/problem?id=2492 Hint Huge input,scanf is recommended. 也是带种类的冰茶几。 由于只分了两类…我们还是可以按照上道题的做法。。 感觉完全是一样的题啊。。 结果一直WA。。。。 最后发现。。。我边读入边判断。。发现同性恋了就直接Break掉了。。。后面改组的数据读到下一组去了233,不WA就日了汪了。。。

poj 1703 Find them, Catch them (并查集)

·539 words·2 mins
http://poj.org/problem?id=1703 种类冰茶几…看到还有一种算是拓展的交加权冰茶几? 看到有做法是在开一个数组。。。记录是哪一组…. 但是因为只有两组….我们可以分别存… 因为不知道每一个D的两个人分别是哪个组(帮派?) 可以都存一下。 TLE了两次….应该是用了cin的事。。。改成scanf就变WA了。。。 想了下。原来是我对“not sure yet”的判断出现失误。 我开了一个v数组,记录在D下出现的人。 我误以为出现的人的帮派一定是确定的。 实际上并不是。 比如 1,3 5,7 3和7都出现了。但是3和7是一组与否显然还是“not sure yet”

codeforces 535 C.Tavas and karafs (解方程)

·556 words·2 mins
http://codeforces.com/problemset/problem/535/C 题读了好几遍才读懂。 题意是给出一个等差数列,操作严格要求从最左边不为零的连续m个数减去1,最多执行t次后问离最左边最远的位置在哪里。 有两个限制条件…一个是本身的si不能大于t,否则无法吃完。 还有一个是从sl到sr的和不能超过m*t (比赛的时候考虑的不周到。。实际上只有当r-l+1比m大的时候才是m,也就是说要取min(m,l-r+1)) 这题正解应该是二分….直接Lower_bound。。。看到也有人用前缀和搞的。 我是解方程了(貌似是个傻逼做法)…. 可以列出一个关于r的一元二次方程。。。然后求根公式2333 方程是:

codeforces 534 C Polycarpus' Dice

·444 words·1 min
http://codeforces.com/problemset/problem/534/C 题意是说一共有N个骰子,第I个筛子一共有di面…现在知道这些骰子的点数之和,问对于每一个骰子不能取得值有多少个。 乍一看有点不明觉厉…稍微再想下,求取值范围即可。