[2018-4-20]BNUZ套题比赛div2 【补题】

又是一次训练赛。。这次A了两题,但是还是卡水题,到底是自己哪里出了问题呢。。。应该重新审视下自己的学习了,不知道问题出在哪,很多水题,同学秒过,然后自己却总是漏判情况,真的心塞。。
A. Mike and Fax
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.

He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.

He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of k palindromes of the same length.

Input

The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000).

The second line contains integer k (1 ≤ k ≤ 1000).

Output

Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.

Examples
Input
Copy
saba
2
Output
Copy
NO
Input
Copy
saddastavvat
2
Output
Copy
YES
Note

Palindrome is a string reading the same forward and backward.

In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".

A题题意就是查看是否全部位回文字符串,题目给K个数字,然后在字符串中找K个回文数,有就yes无就no,水题卡了很长时间,两个办法,分别回转各个间断字符和全部比,还有直接在各个间断找回文串,我是第二次重想打的时候,缺少判断字符串是否能分成K段,所以wa,真的心累。
#include<bits/stdc++.h>
using namespace std;
int t,n,sum,a,b,alen,c,p = 1,acount;
char num[1005];
char x[1005],y[1005];
int main() {
	gets(num);
	scanf("%d",&n);
	alen = strlen(num);
	a = alen / n;
	b = a;
	if(alen % n) {//就是这里 误判结果一直wa
		printf("NO\n");
	} else {
		for(int i = 0; i < alen; i++) {
			for(int j = i + a - 1; j >= i; j--,c++) {
				x[c] = num[j];
			}
			i = a + i - 1;
		}
		for(int i = 0; i < alen; i++) {
			if(num[i] != x[i]) {
				p = 0;
			}
		}
//	puts(num);
//	puts(x);
		if(p) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}

}

 B. Mike and Fun

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/548/problem/A

Description

Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.

They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.

Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.

Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.

Input

The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000).

The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).

The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.

 

Output

After each round, print the current score of the bears.

Sample Input

5 4 5
0 1 1 0
1 0 0 1
0 1 1 0
1 0 0 1
0 0 0 0
1 1
1 4
1 1
4 2
4 3

 

Sample Output

3
4
3
3
4
给定一个n*m的矩阵,都是01的矩阵,然后每次一个操作,改变一个格的值,然后问你当前矩阵中连续为1的最大数是多少,就是按他说的暴力模拟,要预处理,只要把每行的最大值记下来,当改变时,再更新这一行的最大值。
#include<bits/stdc++.h>
 
using namespace std;
const int maxn = 500 + 5;
int a[maxn][maxn];
int num[maxn];
 
int main(){
    int n, m, q, x, y;
    while(cin >> n >> m >> q){
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < m; ++j)
                scanf("%d", &a[i][j]);
        int mm = 0;
        int tt ;
        for(int i = 0; i < n; ++i){
            int cnt = 0;
            for(int j = 0; j < m; ++j){
                if(a[i][j])  ++cnt;
                else  cnt = 0;
                num[i] = max(num[i], cnt);
            }
        }
 
        while(q--){
            scanf("%d %d", &x, &y);
            --x, --y;
            a[x][y] = a[x][y] ? 0 : 1;
            int cnt = 0;
            num[x] = 0;
            for(int i = 0; i < m; ++i){
                if(a[x][i]) ++cnt;
                else  cnt = 0;
                num[x] = max(num[x], cnt);
            }
            mm = 0;
            for(int i = 0; i < n; ++i)  mm = max(mm, num[i]);
            printf("%d\n", mm);
        }
 
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值