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. 创建16x16二级hash目录

    Hash目录是一种优化文件存储性能的方法.无论是Windows还是Linux,无论是NTFS还是ext4,每个目录下所能容纳的项目数是有限的.并不是不能保存,而是当项目数量过大的时候,会降低文件索引速 ...

  2. @RequestMapping 用法详解之地址映射(转)

    引言: 前段时间项目中用到了RESTful模式来开发程序,但是当用POST.PUT模式提交数据时,发现服务器端接受不到提交的数据(服务器端参数绑定没有加任何注解),查看了提交方式为applicatio ...

  3. QT中将ASCII转换为对应数值的方法

    有时候需要将一段ASCII转换为数值进行传输(比如串口) QString str=codeEdit->toPlainText(); QVector<uint>v=str.toUcs4 ...

  4. 【Alpha版本】冲刺-Day1

    队伍:606notconnected 会议时间:11月9日 会议总结 张斯巍(433) 今天安排:设计登陆界面背景,图标的大小规定 完成度:90% 明天计划:主界面图标的修改,侧边栏背景设计,个人信息 ...

  5. jenkins自动化构建iOS应用配置过程中遇到的问题

    最近配置jenkins来自动构建iOS应用,期间遇上不少问题.在这里分享给大家,也给自己留个底,方便下次解决问题. 首先说明下基本情况,我们因为部署jenkins的机器不是Mac,所以不能安装Xcod ...

  6. saltstack(master迁移)

    环境:http://www.cnblogs.com/zzzhfo/p/6126223.html 在添加一台master 把master的/etc/salt目录下的pki打包 上传至第二台master的 ...

  7. iOS开发——高级篇——远程音频、视频播放

    一.远程音频播放(<AVFoundation/AVFoundation.h>) #import <AVFoundation/AVFoundation.h> /** 播放器 */ ...

  8. r-cnn学习(八):minibatch

    这段代码包括由输入图片随机生成相应的RoIs,并生成相应的blobs,由roidb得到相应的 minibatch.其代码如下. # ---------------------------------- ...

  9. Proj.4库的编译及使用

    Proj.4库的编译及使用 Proj.4是开源GIS最著名的地图投影库,GRASS GIS, MapServer, PostGIS, Thuban, OGDI, Mapnik, TopoCad, GD ...

  10. ubuntu和centos安装RRDTool——cacti前置技能

    Installing Pre-Requisites Note that RRDTool 1.0.x versions included all dependancies, but 1.2.x vers ...