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. Asp.net MVC Comet推送

    一.简介 在Asp.net MVC实现的Comet推送的原理很简单. 服务器端:接收到服务器发送的AJAX请求,服务器端并不返回,而是将其Hold住,待到有东西要通知客户端时,才将这个请求返回. 客户 ...

  2. Java编程中“为了性能”需做的26件事

    1.尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载的时间,提高加载的效率,但并不是所有地方都适用于单例,简单来说,单例主要适用于以下三个方面: (1)控制资源的使用,通过线程同步来控制 ...

  3. NOSDK--SDK一键打包及统一接入的实现(前言)

    前言 一,一键打包的实现 1.1 shell脚本执行流程介绍 1.2 自动刷新mk文件的脚本介绍 1.3 编译及拷贝资源的脚本介绍 1.4 打包及签名的脚本介绍 1.5 mac下的脚本环境配置及脚本的 ...

  4. ASP.NET 导出数据表格

    功能:可以实现导出整个数据表格或整个页面 public bool ExportGv(string fileType, string fileName)        {            bool ...

  5. 常见HTTP状态码列表

    HTTP状态码 当浏览者访问一个网页时,浏览者的浏览器会向网页所在服务器发出请求.当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含HTTP状态码的信息头(server header)用以响应 ...

  6. composer的安装以及laravel框架的安装(一)

    laravel号称世界上最好的php框架,没有之一,下面介绍它的安装 laravel学习交流qq群:293798134 composer的安装 : php开发者很多,并且在web开发领域占据绝对统治地 ...

  7. js 制作MD5加密

    主要使用已经写好的JS插件,由于网上有很多,同时自己也可根据原理写出,但为了加快开发速度,我选择了能使用的,写得还不错的js http://pajhome.org.uk/crypt/md5/md5.h ...

  8. word20161206

    D-channel / D 信道 DACL, discretionary access control list / 自由访问控制列表 daily backup / 每日备份 Data Communi ...

  9. StartUML反向(逆向)Java工程通过代码生成类图

     在软件工程中,通过都是先了详细设计,然后按照详细设计来进行开发.在编写详细设计的时候,通常都会画一些类图.时序图.流程图等等UML设计,然后通过uml类图生成代码,这个属于正向工程生成代码,然而在实 ...

  10. mapReduce编程之Recommender System

    1 协同过滤算法 协同过滤算法是现在推荐系统的一种常用算法.分为user-CF和item-CF. 本文的电影推荐系统使用的是item-CF,主要是由于用户数远远大于电影数,构建矩阵的代价更小:另外,电 ...