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.

Sample test(s)
Input
saba
2
Output
NO
Input
saddastavvat
2
Output
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".

题目思路:看串是否能被 k 整除,如果能,在每段里判断这段是否是回文串。

#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream> using namespace std; int main()
{
int k;
char str[];
char s1[];
gets(str);
scanf("%d", &k); int len = strlen(str);
bool flag = false;
if(len % k == ) {
int l = len / k;
for(int i = ; i != len && !flag; i += l) {
for(int j = ; j != l && !flag; ++j) {
if(str[i+j] != str[i+l--j]) {
flag = true;
}
}
}
if(flag == true) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
} else {
cout << "NO" << endl;
}
return ;
}
B. Mike and Fun
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
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
Output
3
4
3
3
4 思路:给你个图,统计每行中,最多有几个连续的“1”,然后再在没行里找个最大的。 注意不能再具体查询的时候再对图进行暴力,复杂度太高。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int arr[][];
int sum[][];
int ans[];
int main() {
int n, m, q;
cin >> n >> m >> q;
memset(sum, , sizeof(sum));
memset(ans, , sizeof(ans));
for(int i = ; i != n; ++i) {
scanf("%d", &arr[i][]);
sum[i][] = (arr[i][] == ) ? : ;
for(int j = ; j != m; ++j) {
scanf("%d", &arr[i][j]);
if(arr[i][j])
sum[i][j] = sum[i][j-] + ;
else
sum[i][j] = ;
}
for(int j = ; j != m; ++j){
ans[i] = max(ans[i], sum[i][j]);
}
} int x, y, Max = ;
while(q--) {
scanf("%d %d", &x, &y);
arr[x-][y-] = arr[x-][y-] == ? : ;
sum[x-][] = (arr[x-][] == ) ? : ;
for(int i = ; i != m; ++i) {
if(arr[x-][i])
sum[x-][i] = sum[x-][i-] + ;
else
sum[x-][i] = ;
}
ans[x-] = ;
for(int i = ; i != m; ++i) {
ans[x-] = max(ans[x-], sum[x-][i]);
}
for(int i = ; i != n; ++i) {
Max = max(Max, ans[i]);
}
printf("%d\n", Max);
Max = ;
}
return ;
}

CodeForces 548的更多相关文章

  1. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  2. Codeforces Round 548 (Div. 2)

    layout: post title: Codeforces Round 548 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  3. Codeforces Round #548 (Div. 2) F splay(新坑) + 思维

    https://codeforces.com/contest/1139/problem/F 题意 有m个人,n道菜,每道菜有\(p_i\),\(s_i\),\(b_i\),每个人有\(inc_j\), ...

  4. Codeforces Round #548 (Div. 2) E 二分图匹配(新坑) or 网络流 + 反向处理

    https://codeforces.com/contest/1139/problem/E 题意 有n个学生,m个社团,每个学生有一个\(p_i\)值,然后每个学生属于\(c_i\)社团, 有d天,每 ...

  5. CodeForces Round #548 Div2

    http://codeforces.com/contest/1139 A. Even Substrings You are given a string s=s1s2…sns=s1s2…sn of l ...

  6. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  7. C. Edgy Trees Codeforces Round #548 (Div. 2) 并查集求连通块

    C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #548

    没打,简单补档 C.Edgy Trees 容斥,把黑边断掉数联通块,每个联通块贡献$siz^k$ #include<cstdio> #include<cstring> #inc ...

  9. Codeforces Round #548 (Div. 2) D 期望dp + 莫比乌斯反演

    https://codeforces.com/contest/1139/problem/D 题意 每次从1,m中选一个数加入队列,假如队列的gcd==1停止,问队列长度的期望 题解 概率正着推,期望反 ...

随机推荐

  1. 线程间通信 GET POST

    线程间通信有三种方法:NSThread   GCD  NSOperation       进程:操作系统里面每一个app就是一个进程. 一个进程里面可以包含多个线程,并且我们每一个app里面有且仅有一 ...

  2. Jquery动态添加的元素绑定事件的3种方法

    假设我们点击li标签,弹出他的文本,如果是动态添加的li,点击是没有效果的,压根弹不出来文本. 下面博主分享一下为动态添加的元素绑定事件的三种方法,网上一般都是两种,我在这里多增加了一种. 事件案例: ...

  3. CentOS个人目录下中文路径转英文路径

    CentOS个人目录下中文路径转英文路径 如果安装了中文版到CentOS之后,root目录及home目录下会出现中文到路径名,如"桌面"."文档"," ...

  4. CentOS7下搭建邮件服务器(dovecot + postfix + SSL)

    CentOS   花了基本上两天的时间去配置CentOS7下的邮件服务器.其中艰辛太多了,一定得总结下. 本文的目的在于通过一系列配置,在CentOS 7下搭建dovecot + postfix + ...

  5. C语言基础(2)-常量

    常量就是在程序运行中不可变化的量. #define #define MAX 100 定义了一个常量名字叫MAX,值是100,用#define定义的常量一般用大写字母. #define是一个预编译指令, ...

  6. linux /proc/meminfo 文件分析(转载)

    cat /proc/meminfo    读出的内核信息进行解释,下篇文章会简单对读出该信息的代码进行简单的分析. # cat /proc/meminfo MemTotal:     kB MemFr ...

  7. Windows下安装MongoDB

    项目当中用到MongoDB最为NoSQL数据库,运行的平台为 Windows Server 2008,下面是MongoDB的安装过程笔记: 1.下载软件 官方下载地址:http://www.mongo ...

  8. 字符串匹配:KMP算法

    一.原理: KMP算法是由Knuth,Morris,Pratt共同提出的模式匹配算法,其对于任何模式和目标序列,都可以在线性时间内完成匹配查找,而不会发生退化,是一个非常优秀的模式匹配算法.朴素算法( ...

  9. 学习 opencv---(3) ROI 区域图像叠加&初级图像混合

    在这篇文章里,我们一起学习了在OpenCV中如何定义感兴趣区域ROI,如何使用addWeighted函数进行图像混合操作,以及将ROI和addWeighted函数结合起来使用,对指定区域进行图像混合操 ...

  10. alert 替代效果smoke.js

    在一些表单等需要弹窗提醒的时候,每个浏览器都有一个alert(),comfirm()函数能弹出信息,但是浏览器的自带的这种效果样式不统一,而且都固定在页面顶部: smoke.js轻量级的JS插件,他标 ...